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

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

Open
carlosgarciaq opened this issue May 28, 2013 · 4 comments · May be fixed by #312
Open

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

carlosgarciaq opened this issue May 28, 2013 · 4 comments · May be fixed by #312

Comments

@carlosgarciaq
Copy link

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?

@codegourmet
Copy link

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) %>
...

@abacha
Copy link

abacha commented Sep 11, 2013

+1

@panupan
Copy link

panupan commented Nov 27, 2013

+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

@singpolyma
Copy link

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

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

Successfully merging a pull request may close this issue.

5 participants