nested_form icon indicating copy to clipboard operation
nested_form copied to clipboard

Associations with more than one add-link (initialization model)

Open carlosgarciaq opened this issue 12 years ago • 4 comments
trafficstars

Hey, thank you very much for developing this wonderful gem! It's done my life easier. I'm using it in my project for 2 of my forms and in one I'm finding that having two types of add-links (with different model_object) could be useful. It's a situation similar to this:

<%= nested_form_for @receipt do |f| %>
  ...
  <%= f.link_to_add "Add a good", :products, :model_object => Product.new(:kind => 'good') %>
  <%= f.link_to_add "Add a service", :products, :model_object => Product.new(:kind => 'service') %>
<% end %>

I think right now this is not supported, only one blueprint is created and both links would insert a product of type 'good'.

Do you think it could be modified easily to do it? Do you see any drawbacks? Manipulating the code in your Railscasts nr. 197 (nested model form pt. 2) this is pretty easy but there are no blueprints there.

This could also help to work with polymorphic associations. Would the gem work with polymorphic associations, btw?

carlosgarciaq avatar May 28 '13 10:05 carlosgarciaq

This is probably a duplicate of [edit: rather "related to" than duplicate] Issue #237.

I have the same issue, in my case it's with a polymorphic model:

<%= f.link_to_add "Add a Text Component", :components, :model_object => TextComponent.new) %>
<%= f.link_to_add "Add an Image Component", :components, :model_object => ImageComponent.new) %>
...

codegourmet avatar Jun 22 '13 11:06 codegourmet

+1

abacha avatar Sep 11 '13 12:09 abacha

+1

Looks like blueprint_id generation might need to be updated to support this: https://github.com/ryanb/nested_form/blob/master/lib/nested_form/builder_mixin.rb#L106

panupan avatar Nov 27 '13 19:11 panupan

This would require another param that would be the name of this "type" of blueprint.

singpolyma avatar Mar 10 '14 21:03 singpolyma