Kishoj B. wrote in post #959256:
> How to assign the value in ruby commands in file with extension
> html.erb for the following scenario:
> Comment.request_id =  id (of Request)
> Note Comment and Request both are model

There's so much wrong with what I see here I don't know where to start. 
You really need to study the Model-View-Controller (MVC) design pattern. 
Otherwise you'll never get Rails to work for you as it was designed to 
do.

But, here are the top five things I see wrong:

5. Request is probably a bad name for a model class in web applications. 
It's could be too easily confused with the actual HTTP request object.

4. The request_id appears to be an instance method, but you're showing 
it called on the Comment class.

3. Don't manipulate primary and foreign keys directly. Manage 
associations through association manipulation methods.

@comment = @request.comments.build(:title => "Learn MVC", :author => 
"Robert")

@request.comments << an_existing_comment

Note: What you see here is controller code not view code.

2. Fetching data IS NOT the responsibility of the view.

RequestController (request_controller.rb)
-------------------------------------
@my_request = Request.find(params[:id])

1. Manipulation of data IS NOT the responsibility of the view.

You need a CommentsController class that is used to fetch data from the 
Comment model and provide that data to one of the views. User input is 
provided to the controller though the params hash and the model objects 
are provided to the view through instance variables in the controller. 
These get pushed (or copied) into the view. This means that the 
"Comment" and/or "Request" model objects would be available to the view 
as @comment or @request (or whatever names to give to the instance 
variables).

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to