I''ve just started working with Rails. And I can''t figure out what seems to be the easiest thing imaginable. I need to send @ferry.id from a view in ferry_controller... <%= link_to ''Add new schedule'', {:controller => ''schedule'', :action => ''new'', ferry_id => @ferry.id }%></d> to a method in schedule_controller... def new @schedule = Schedule.new end and have that value survive into the ''new'' view where it will be returned in Schedule.new(params[:schedule]). How is this done? I''m must be utterly simple but I can''t figure it out. Gavin --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Pat Maddox
2007-Jul-25 22:54 UTC
Re: Any programmer can answer this in 2 sec, but I''m stumped.
On 7/25/07, Gavin <gavhug-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I''ve just started working with Rails. And I can''t figure out what > seems to be the easiest thing imaginable. I need to send @ferry.id > from a view in ferry_controller... > > <%= link_to ''Add new schedule'', {:controller => ''schedule'', :action => > ''new'', ferry_id => @ferry.id }%></d> > > to a method in schedule_controller... > > def new > @schedule = Schedule.new > end > > and have that value survive into the ''new'' view where it will be > returned in Schedule.new(params[:schedule]). > > How is this done? I''m must be utterly simple but I can''t figure it > out. > > Gavin > > > > >Hey Gavin, You can create an instance variable the same as you do with the schedule. @ferry_id = params[:ferry_id] If the ferry_id is part of the schedule, then you might want to create the Schedule object with the ferry id @schedule = Schedule.new :ferry_id => params[:ferry_id] In either case you''ll need a hidden tag on the new page, so the param gets passed into the create action. If you do things the second way you just do <%= f.hidden_field :ferry_id %> and it''ll be slurped up in params[:schedule] Pat --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Gavin
2007-Jul-25 23:58 UTC
Re: Any programmer can answer this in 2 sec, but I''m stumped.
Hey Pat Thanks for the quick reply. I''m still not sure how the @ferry_id travels from my ferry_controller''s view to the schedule_controller. Is it something like this: <%= link_to ''Add new schedule'', {:controller => ''schedule'', :action => ''new'', ferry_id => @ferry.id }%> then this: def new(*args) @schedule = Schedule.new :ferry_id => params[:ferry_id] end Something stills feels awkward about it. Gavin On Jul 25, 6:54 pm, "Pat Maddox" <perg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 7/25/07, Gavin <gav...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > I''ve just started working with Rails. And I can''t figure out what > > seems to be the easiest thing imaginable. I need to send @ferry.id > > from a view in ferry_controller... > > > <%= link_to ''Add new schedule'', {:controller => ''schedule'', :action => > > ''new'', ferry_id => @ferry.id }%></d> > > > to a method in schedule_controller... > > > def new > > @schedule = Schedule.new > > end > > > and have that value survive into the ''new'' view where it will be > > returned in Schedule.new(params[:schedule]). > > > How is this done? I''m must be utterly simple but I can''t figure it > > out. > > > Gavin > > Hey Gavin, > > You can create an instance variable the same as you do with the schedule. > @ferry_id = params[:ferry_id] > > If the ferry_id is part of the schedule, then you might want to create > the Schedule object with the ferry id > @schedule = Schedule.new :ferry_id => params[:ferry_id] > > In either case you''ll need a hidden tag on the new page, so the param > gets passed into the create action. If you do things the second way > you just do > <%= f.hidden_field :ferry_id %> > > and it''ll be slurped up in params[:schedule] > > Pat--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Pat Maddox
2007-Jul-26 00:08 UTC
Re: Any programmer can answer this in 2 sec, but I''m stumped.
That''s precisely it, except you''ll use :ferry_id in the link_to call of course. How does it feel awkward to you? Pat On 7/25/07, Gavin <gavhug-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hey Pat > > Thanks for the quick reply. I''m still not sure how the @ferry_id > travels from my ferry_controller''s view to the schedule_controller. > Is it something like this: > > <%= link_to ''Add new schedule'', {:controller => ''schedule'', :action => > ''new'', ferry_id => @ferry.id }%> > > then this: > > def new(*args) > @schedule = Schedule.new :ferry_id => params[:ferry_id] > end > > Something stills feels awkward about it. > > Gavin > > > On Jul 25, 6:54 pm, "Pat Maddox" <perg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > On 7/25/07, Gavin <gav...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > > > > > > I''ve just started working with Rails. And I can''t figure out what > > > seems to be the easiest thing imaginable. I need to send @ferry.id > > > from a view in ferry_controller... > > > > > <%= link_to ''Add new schedule'', {:controller => ''schedule'', :action => > > > ''new'', ferry_id => @ferry.id }%></d> > > > > > to a method in schedule_controller... > > > > > def new > > > @schedule = Schedule.new > > > end > > > > > and have that value survive into the ''new'' view where it will be > > > returned in Schedule.new(params[:schedule]). > > > > > How is this done? I''m must be utterly simple but I can''t figure it > > > out. > > > > > Gavin > > > > Hey Gavin, > > > > You can create an instance variable the same as you do with the schedule. > > @ferry_id = params[:ferry_id] > > > > If the ferry_id is part of the schedule, then you might want to create > > the Schedule object with the ferry id > > @schedule = Schedule.new :ferry_id => params[:ferry_id] > > > > In either case you''ll need a hidden tag on the new page, so the param > > gets passed into the create action. If you do things the second way > > you just do > > <%= f.hidden_field :ferry_id %> > > > > and it''ll be slurped up in params[:schedule] > > > > Pat > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Gavin
2007-Jul-26 00:48 UTC
Re: Any programmer can answer this in 2 sec, but I''m stumped.
Hey! It works! I came from C# and .net and it seems to me that the syntax in Ruby and Rails is less clear. I''ve only been at it for a week though...probably just need more time to let it soak in. Thanks for the help, Pat. Gavin On Jul 25, 8:08 pm, "Pat Maddox" <perg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> That''s precisely it, except you''ll use :ferry_id in the link_to call of course. > > How does it feel awkward to you? > > Pat > > On 7/25/07, Gavin <gav...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Hey Pat > > > Thanks for the quick reply. I''m still not sure how the @ferry_id > > travels from my ferry_controller''s view to the schedule_controller. > > Is it something like this: > > > <%= link_to ''Add new schedule'', {:controller => ''schedule'', :action => > > ''new'', ferry_id => @ferry.id }%> > > > then this: > > > def new(*args) > > @schedule = Schedule.new :ferry_id => params[:ferry_id] > > end > > > Something stills feels awkward about it. > > > Gavin > > > On Jul 25, 6:54 pm, "Pat Maddox" <perg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > On 7/25/07, Gavin <gav...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > I''ve just started working with Rails. And I can''t figure out what > > > > seems to be the easiest thing imaginable. I need to send @ferry.id > > > > from a view in ferry_controller... > > > > > <%= link_to ''Add new schedule'', {:controller => ''schedule'', :action => > > > > ''new'', ferry_id => @ferry.id }%></d> > > > > > to a method in schedule_controller... > > > > > def new > > > > @schedule = Schedule.new > > > > end > > > > > and have that value survive into the ''new'' view where it will be > > > > returned in Schedule.new(params[:schedule]). > > > > > How is this done? I''m must be utterly simple but I can''t figure it > > > > out. > > > > > Gavin > > > > Hey Gavin, > > > > You can create an instance variable the same as you do with the schedule. > > > @ferry_id = params[:ferry_id] > > > > If the ferry_id is part of the schedule, then you might want to create > > > the Schedule object with the ferry id > > > @schedule = Schedule.new :ferry_id => params[:ferry_id] > > > > In either case you''ll need a hidden tag on the new page, so the param > > > gets passed into the create action. If you do things the second way > > > you just do > > > <%= f.hidden_field :ferry_id %> > > > > and it''ll be slurped up in params[:schedule] > > > > Pat--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---