开发者

Ruby on Rails Multiple has_many choice in form

开发者 https://www.devze.com 2023-02-04 17:22 出处:网络
I have two tables in my rails application Categories and Projects. The relationship between both 开发者_C百科is has_many both ways, meaning Project has_may Categories and Categories has_many Projects.

I have two tables in my rails application Categories and Projects. The relationship between both 开发者_C百科is has_many both ways, meaning Project has_may Categories and Categories has_many Projects. The Categories tables are setup as a tree so that each category which is not a root has a father.

I am interested in changing the new and edit action form so that multiple categories can be selected in the process with a tree checkbox display. If possible i would also like any checking of a node on the category tree to select its whole subtree (all it's descendants). Of course the new and edit action must create the has_many dependencies.

Thanks, Nachshon


Have you tried formtastic? I think you could just do

<%= f.inputs :categories, :as => :checkboxes %> // :as => :select is another option

with it. I'm not sure how to do it with basic ActionView::FormBuilder though.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号