ryanb / nested_form

Rails plugin to conveniently handle multiple models in a single form.
MIT License
1.79k stars 505 forks source link

Can I add different subform (using STI)? #360

Open twnaing opened 8 years ago

twnaing commented 8 years ago

I have the following models

class Item
    has_many subitems
    accepts_nested_attributes_for subitems
end 

class Subitem
end

class Diamond < Subitem
end

class Gold < Subitem
end

I want to render Gold subform or Diamond Subform accordingly.

From this wiki I could pass data with the following syntax

- fields_for subitems do |si|
    = si.link_to_add 'Gold', :subitems, :'data-predefined-name' => 'Gold'
    = si.link_to_add 'Diamond', :subitems, :'data-predefined-name' => 'Diamond'

According to Enhanced jQuery javascript template, I think, I need to change the content in the form generation.

Do I need to change the source code? Can I do that in a more elegant way?

yfractal commented 8 years ago

@twnaing Hi, I have same issue. May you give me some insight about how to do these without use the Enhanced jQuery javascript template ?

twnaing commented 8 years ago

@yfractal , I read Ryan's Nested Form screencast comment and used cocoon gem for my requirement.

nested_form rocks and I still using nested_form for others.

yfractal commented 8 years ago

@twnaing it looks cool, thank you very much.