I have a has_many :through companies <-> markets with emails as the join table.
The view is relatively easy:
<% form_for :market, :html => { :id => 'marketform' } do |f|%> <%= hidden_field_tag "company[companyid]", @company.id, :index => @company.id %> <% for market in @markets %> <div> <%= check_box_tag "company[market_attributes]", market.id, @company.markets.include?(market) %> <%= label_tag :market_ids, market.name.upcase -%> <span style="align: right;"><%= text_field_tag "emaildistro[# {market.id}]" %></span> </div> <% end %> <input type="submit" value="Update Markets" onclick="Modalbox.show('/ markets/create', {method: 'post' ,title: 'Sending status', params: Form.serialize('marketform') }); return false;" /> <% end %>
controller:
company = Contactcompany.find(params[:company][:companyid]) markets = params[:company][:market_attributes] ||= company.market_ids = markets company.emails.each{|mail| distro = params[:emaildistro]["#{mail.market.id}"] mail.update_attributes(:emaildistro => distro) }
Is there a way to retrieve the emails just like the checkboxes do when you pull up the view?