Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

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

Open
twnaing opened this issue Nov 12, 2015 · 3 comments
Open

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

twnaing opened this issue Nov 12, 2015 · 3 comments

Comments

@twnaing
Copy link

twnaing commented Nov 12, 2015

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
Copy link

@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
Copy link
Author

twnaing commented Dec 21, 2015

@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
Copy link

@twnaing it looks cool, thank you very much.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants