Hi, I currently am using acts as tree for building site navigation. When a new page is added to the site, a select option with the include blank option gets populated to determine the correct parent for the new page. I would like the blank option to be set to 0 for root status. I tried creating a quick test in the controller to see if the params[:parent_id] is nil and then assigning a 0 to it but it did not work. Can anyone offer any help with this? Thanks! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Shai Shefer wrote:> Hi, > > I currently am using acts as tree for building site navigation. When a > new page is added to the site, a select option with the include blank > option gets populated to determine the correct parent for the new > page. I would like the blank option to be set to 0 for root status. > > I tried creating a quick test in the controller to see if the > params[:parent_id] is nil and then assigning a 0 to it but it did not > work. Can anyone offer any help with this? > > Thanks!You can construct the options yourself, and insert the blank option manually with array addition: f.select :parent_id, [['''', 0]] + select_parent_options Where select_parent_options is a helper like: def select_parent_options Page.find(:all).collect do |p| [p.title, p.id] end end This makes sure that your blank line returns 0 instead of nil. -- 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 -~----------~----~----~----~------~----~------~--~---
> You can construct the options yourself, and insert the blank option > manually with array addition: > > f.select :parent_id, [['''', 0]] + select_parent_options > > Where select_parent_options is a helper like: > > def select_parent_options > Page.find(:all).collect do |p| > [p.title, p.id] > end > end >Ah ha! Thanks, I was trying this but added the ['''', 0] to the actual select helper, this helps a ton! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---