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 -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 10-11-04 04:12 AM, kishoj wrote:> 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 >move code into the controller or model -- Kind Regards, Rajinder Yadav | DevMentor.org | Do Good! ~ Share Freely GNU/Linux: 2.6.35-22-generic Kubuntu x86_64 10.10 | KDE 4.5.1 Ruby 1.9.2p0 | Rails 3.0.1 -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 modelThere''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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thank you all for your warm response!!! I got the solution. Its something like below <% form_for [@request, Comment.new] do |f| %> <p> <%= f.hidden_field :request_id, :value => @request.id %> ................................... </p> ................................................................................. <% end %> On Nov 5, 12:27 am, Robert Walker <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> 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 viahttp://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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Nov 5, 3:25 pm, kishoj <kis...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thank you all for your warm response!!! > I got the solution. Its something like below > > <% form_for [@request, Comment.new] do |f| %> > <p> > <%= f.hidden_field :request_id, :value => @request.id %> > ................................... > </p> > ................................................................................. > <% end %>You can avoid the hidden field if you setup a nested route for request/ ##/comments. http://guides.rubyonrails.org/routing.html#nested-resources -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.