Hi, I previously had a nested resources system with user having many events and events having many signups. But i thought it was not needed and am now trying a new approach without nested resources. The problem is now that when i try to create a new signup, which should be related to the id of the event with event_id in the signups table, i get a "Couldn''t find Event without an ID" error, which i understand because the url contains just signups/new and the action wants to find event_id in the params. In otherwords i was looking for a way to send the event id to the signup controllers new action without having nested resources. is it possible? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
betaband wrote:> Hi, I previously had a nested resources system with user having many > events and events having many signups. But i thought it was not needed > and am now trying a new approach without nested resources. > The problem is now that when i try to create a new signup, which > should be related to the id of the event with event_id in the signups > table, i get a "Couldn''t find Event without an ID" error, which i > understand because the url contains just signups/new and the action > wants to find event_id in the params. > In otherwords i was looking for a way to send the event id to the > signup controllers new action without having nested resources. is it > possible? > > > >sure. new_signup_path(:event_id => 1) will generate... /signups/new?event_id=1 which will get the :event_id into your params but... would you prefer something more elegant??? (like what you had) /events/1/signups/new -- http://www.5valleys.com/ http://www.workingwithrails.com/person/8078 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
its true, it is more elegant. I just wanted to try to keep the resources un-nested to save confusion when linking because its one of my first rails apps. But its good anyways to know that its possible with both. thanks. On Mar 12, 7:06 pm, Jon Garvin <jgarvin.li...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> betaband wrote: > > Hi, I previously had a nested resources system with user having many > > events and events having many signups. But i thought it was not needed > > and am now trying a new approach without nested resources. > > The problem is now that when i try to create a new signup, which > > should be related to the id of the event with event_id in the signups > > table, i get a "Couldn''t find Event without an ID" error, which i > > understand because the url contains just signups/new and the action > > wants to find event_id in the params. > > In otherwords i was looking for a way to send the event id to the > > signup controllers new action without having nested resources. is it > > possible? > > sure. > new_signup_path(:event_id => 1) will generate... > /signups/new?event_id=1 > which will get the :event_id into your params > > but... would you prefer something more elegant??? (like what you had) > > /events/1/signups/new > > --http://www.5valleys.com/http://www.workingwithrails.com/person/8078--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
You can actually nest resources in different combinations. For example, you could have: map.resources :users do |user| user.resources :events end map.resources :events do |event| event.resources :signups end map.resources :locations do |location| location.resources :events end You''re not limited to listing a ''resource'' in only one place in the routing map, nor are you restricted to its position (ie., once nested, always nested). With the routing above, you can do the following: SignupsController def new @event = Event.find(params[:event_id]) if params[:event_id] @signup = @event ? @event.signups.build : Signup.new end view: new_event_signup_path(@event) On Mar 12, 2:56 pm, betaband <nospacesallonew...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> its true, it is more elegant. I just wanted to try to keep the > resources un-nested to save confusion when linking because its one of > my first rails apps. But its good anyways to know that its possible > with both. thanks. > > On Mar 12, 7:06 pm, Jon Garvin <jgarvin.li...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > betaband wrote: > > > Hi, I previously had a nested resources system with user having many > > > events and events having many signups. But i thought it was not needed > > > and am now trying a new approach without nested resources. > > > The problem is now that when i try to create a new signup, which > > > should be related to the id of the event with event_id in the signups > > > table, i get a "Couldn''t find Event without an ID" error, which i > > > understand because the url contains just signups/new and the action > > > wants to find event_id in the params. > > > In otherwords i was looking for a way to send the event id to the > > > signup controllers new action without having nested resources. is it > > > possible? > > > sure. > > new_signup_path(:event_id => 1) will generate... > > /signups/new?event_id=1 > > which will get the :event_id into your params > > > but... would you prefer something more elegant??? (like what you had) > > > /events/1/signups/new > > > --http://www.5valleys.com/http://www.workingwithrails.com/person/8078--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---