Has_many :through , extra data retrieval


#1

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


<%= check_box_tag “company[market_attributes][]”, market.id,
@company.markets.include?(market) %>
<%= label_tag :market_ids, market.name.upcase -%>
<%= text_field_tag “emaildistro[#
{market.id}]” %>


<% end %>

<% 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?