Hey fellas, I have an Organization model with many projects. I have a link to a new project from the organization''s show view, like so: new_organization_project_path (@organization). I was hoping Rails would get the id of the organization from the instance I am passing and populate project.organization_id, but to no avail. The db rollbacks back and get redirected to the new project page. Any ideas? How would you normally do this? Best, -- 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 To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/0kliAF2uyWEJ. For more options, visit https://groups.google.com/groups/opt_out.
What path do you get? It should be something like "/organizations/:id/projects/new". This is where you can add a form for example to add a new project. Do you try to POST to that path above? If so, that''s wrong (it''s for GET requests). Read more about nested resources here: http://guides.rubyonrails.org/routing.html#nested-resources //Linus Den torsdagen den 1:e november 2012 kl. 22:02:36 UTC+1 skrev why-el:> > Hey fellas, > > I have an Organization model with many projects. I have a link to a new > project from the organization''s show view, like so: > new_organization_project_path (@organization). I was hoping Rails would get > the id of the organization from the instance I am passing and populate > project.organization_id, but to no avail. The db rollbacks back and get > redirected to the new project page. Any ideas? How would you normally do > this? > > Best, >-- 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 To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/XY7Vuqws-yUJ. For more options, visit https://groups.google.com/groups/opt_out.
On 1 November 2012 21:02, why-el <wael.khobalatte-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hey fellas, > > I have an Organization model with many projects. I have a link to a new > project from the organization''s show view, like so: > new_organization_project_path (@organization). I was hoping Rails would get > the id of the organization from the instance I am passing and populate > project.organization_id, but to no avail. The db rollbacks back and get > redirected to the new project page. Any ideas? How would you normally do > this?Have a look at the the Rails Guide on debugging. It will show you techniques that you can use to debug your code. Hint - start by looking in development.log to see what action is called and what the parameters are. Colin -- 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 https://groups.google.com/groups/opt_out.
Yes that''s what I get as a path. I have solved this issue. Its silly really, it turns out I needed to make an @organization instance available throughout my projectsController, so I made a before filter to fetch it based on the url. Quick question though, do I need to update all the controller methods to reference the parent model whenever I have a one to many relationship like this one (changing everything to @organization.projects.someMethod)? This looks tedious to me. Does Rails help with this? On Thursday, November 1, 2012 9:12:00 PM UTC, Linus Pettersson wrote:> > What path do you get? It should be something like > "/organizations/:id/projects/new". This is where you can add a form for > example to add a new project. > > Do you try to POST to that path above? If so, that''s wrong (it''s for GET > requests). Read more about nested resources here: > http://guides.rubyonrails.org/routing.html#nested-resources > > //Linus > > > Den torsdagen den 1:e november 2012 kl. 22:02:36 UTC+1 skrev why-el: >> >> Hey fellas, >> >> I have an Organization model with many projects. I have a link to a new >> project from the organization''s show view, like so: >> new_organization_project_path (@organization). I was hoping Rails would get >> the id of the organization from the instance I am passing and populate >> project.organization_id, but to no avail. The db rollbacks back and get >> redirected to the new project page. Any ideas? How would you normally do >> this? >> >> Best, >> >-- 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 To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/KvGh7CNSn8wJ. For more options, visit https://groups.google.com/groups/opt_out.
On 1 November 2012 23:32, why-el <wael.khobalatte-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Yes that''s what I get as a path. I have solved this issue. Its silly really, > it turns out I needed to make an @organization instance available throughout > my projectsController, so I made a before filter to fetch it based on the > url.As a beginner I suggest you work through a good tutorial on Rails to give you understanding of the basics. railstutorial.org is good and is free to use online.> > Quick question though, do I need to update all the controller methods to > reference the parent model whenever I have a one to many relationship like > this one (changing everything to @organization.projects.someMethod)? This > looks tedious to me. Does Rails help with this?I don''t understand the question. Can you give a particular example? Colin> > > On Thursday, November 1, 2012 9:12:00 PM UTC, Linus Pettersson wrote: >> >> What path do you get? It should be something like >> "/organizations/:id/projects/new". This is where you can add a form for >> example to add a new project. >> >> Do you try to POST to that path above? If so, that''s wrong (it''s for GET >> requests). Read more about nested resources here: >> http://guides.rubyonrails.org/routing.html#nested-resources >> >> //Linus >> >> >> Den torsdagen den 1:e november 2012 kl. 22:02:36 UTC+1 skrev why-el: >>> >>> Hey fellas, >>> >>> I have an Organization model with many projects. I have a link to a new >>> project from the organization''s show view, like so: >>> new_organization_project_path (@organization). I was hoping Rails would get >>> the id of the organization from the instance I am passing and populate >>> project.organization_id, but to no avail. The db rollbacks back and get >>> redirected to the new project page. Any ideas? How would you normally do >>> this? >>> >>> Best, > > -- > 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 > To view this discussion on the web visit > https://groups.google.com/d/msg/rubyonrails-talk/-/KvGh7CNSn8wJ. > > For more options, visit https://groups.google.com/groups/opt_out. > >-- 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 https://groups.google.com/groups/opt_out.