Skip to content

Instantly share code, notes, and snippets.

@marcelojunior
Created April 13, 2015 21:25
Show Gist options
  • Save marcelojunior/ac66b3ba0ccfef1dcf3f to your computer and use it in GitHub Desktop.
Save marcelojunior/ac66b3ba0ccfef1dcf3f to your computer and use it in GitHub Desktop.
# Models
class Manager::Ad::ThemedCampaign < ActiveRecord::Base
has_and_belongs_to_many :products
accepts_nested_attributes_for :products, reject_if: :all_blank, allow_destroy: true
end
class Manager::Ad::Product < ActiveRecord::Base
has_and_belongs_to_many :themed_campaigns
end
# View
# _form.html.erb
...
<%= f.simple_fields_for :products do |product| %>
<%= render 'product_fields', f: product %>
<% end %>
...
# _product_field.html.erb
<div class="col-md-2">
<%= f.input :id %>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment