I''m new to Rails and this is surely and super easy question. I have a show_companies.rhtml that produces a list of ships for each company. I have an add_ship link next to each company which goes through the controller to a new_ship view. How do I pass the company_id from the original to this new view so I can have the company_id available when I create the ship? --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
:id => @company which is a quick way of saying :id => @company.id --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I''m doing this simple thing: <% form_for :ferry do |f| %> <%= f.hidden_field :company_id, :value => @company.id %> Ferry name:<br /> <%= f.text_field :name %> <%= submit_tag %> <% end %> ...but I get this exception: Couldn''t find Company without an ID. Parameters: {"commit"=>"Save changes", "authenticity_token"=>"5398f203e605b0cbbeefe5123a67c3c3c424de8b", "ferry"=>{"name"=>"adf", "company_id"=>"4"}} I can see the ID right there in the parameters. Why won''t it save? On Oct 11, 7:33 pm, "Franz Strebel" <franz.stre...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> :id => @company > > which is a quick way of saying :id => @company.id--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
in the controller u need to define @project = Project.find(params[:id]) and then call @project.save method to make it work i think this should work propely -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Well, I got it working, but I don''t know why the change made any difference. On the controller, I changed @company = Company.find(params[:company_id]) to @company_id params[:company_id] and in the view <%= f.hidden_field :company_id, :value => @company.id %> to ... :value => @company_id %> The resulting type and assignment appears exactly the same to me. Anyone know what the difference is? Gavin On Oct 11, 9:00 pm, Dhaval Parikh <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> in the controller u need to define @project = Project.find(params[:id]) > and then call @project.save method to make it work i think this should > work propely > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 10/11/07, Gavin <gavhug-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I''m doing this simple thing: > > <% form_for :ferry do |f| %> > <%= f.hidden_field :company_id, :value => @company.id %> > Ferry name:<br /> > <%= f.text_field :name %> > <%= submit_tag %> > <% end %> > > ...but I get this exception: > > Couldn''t find Company without an ID. > > Parameters: > {"commit"=>"Save changes", > "authenticity_token"=>"5398f203e605b0cbbeefe5123a67c3c3c424de8b", > "ferry"=>{"name"=>"adf", > "company_id"=>"4"}} > > I can see the ID right there in the parameters. Why won''t it save?The error is coming from your controller code. I''m guessing (since you didn''t show the code) that you have something like: @company = Company.find(params[:id]) Based on the way you''ve set up your form, you would have to access the parameter as: @company = Company.find params[:ferry][:company_id] But before you just throw that line of code in, step back for a sec. You''re not really approaching this correctly. You need to get a basic Rails book and work your way through it. Rails is "opinionated", so if you learn to work with it instead of against it your life will be easier. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---