Hi, Noob here, so apologies in advance for my certain misunderstandings. I have hierarchal category structure which I''ve modeled using acts_as_trees. I have successfully created the code to display the categories in a tree-ish fashion (it was very easy - I''m impressed). I would like to let users add new subcategories to an existing category by clicking on a "new subcategory" link next to each category name in this tree. I am having problems doing this. My approach has been: In the href of the "new subcategory" html, I stick the id of the parent like this: <a href="/categories/new?parent_id=1"> I can pick up the parent_id in the new action controller easily enough: @category = Category.new @category.parent = Category.find(params[:parent_id]) But I loose it when I get to the create action controller, as the form does not have the parent_id (nor do I want it to). The I guess my basic issue is that I set up the parent that I want to use in the list rendering, but I can''t pass it all the way through to the create action. Any suggestions? Thanks, Alex --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
the common method for cases like this is to save the parent_id in a hidden field in the form. Or save it in the session. Or put it as a parameter in URL that the the form is calling. On 10 Apr., 03:03, "alex" <anlee...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > Noob here, so apologies in advance for my certain misunderstandings. > > I have hierarchal category structure which I''ve modeled using > acts_as_trees. I have successfully created the code to display the > categories in a tree-ish fashion (it was very easy - I''m impressed). > I would like to let users add new subcategories to an existing > category by clicking on a "new subcategory" link next to each category > name in this tree. I am having problems doing this. > > My approach has been: > > In the href of the "new subcategory" html, I stick the id of the > parent like this: > <a href="/categories/new?parent_id=1"> > > I can pick up the parent_id in the new action controller easily > enough: > @category = Category.new > @category.parent = Category.find(params[:parent_id]) > > But I loose it when I get to the create action controller, as the form > does not have the parent_id (nor do I want it to). > > The I guess my basic issue is that I set up the parent that I want to > use in the list rendering, but I can''t pass it all the way through to > the create action. > > Any suggestions? > > Thanks, > Alex--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Ok, thanks. I''ll give the hidden field method a try. On Apr 10, 5:56 am, "Thorsten" <duple...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> the common method for cases like this is to save the parent_id in a > hidden field in the form. > Or save it in the session. > Or put it as a parameter in URL that the the form is calling. > > On 10 Apr., 03:03, "alex" <anlee...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Hi, > > > Noob here, so apologies in advance for my certain misunderstandings. > > > I have hierarchal category structure which I''ve modeled using > > acts_as_trees. I have successfully created the code to display the > > categories in a tree-ish fashion (it was very easy - I''m impressed). > > I would like to let users add new subcategories to an existing > > category by clicking on a "new subcategory" link next to each category > > name in this tree. I am having problems doing this. > > > My approach has been: > > > In the href of the "new subcategory" html, I stick the id of the > > parent like this: > > <a href="/categories/new?parent_id=1"> > > > I can pick up the parent_id in the new action controller easily > > enough: > > @category = Category.new > > @category.parent = Category.find(params[:parent_id]) > > > But I loose it when I get to the create action controller, as the form > > does not have the parent_id (nor do I want it to). > > > The I guess my basic issue is that I set up the parent that I want to > > use in the list rendering, but I can''t pass it all the way through to > > the create action. > > > Any suggestions? > > > Thanks, > > Alex- Hide quoted text - > > - Show quoted text ---~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---