Forum: Ruby on Rails has_many :through , extra data retrieval.

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Chris H. (Guest)
on 2009-05-12 23:16
(Received via mailing list)
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]",, :index => %>
  <% for market in @markets %>
      <%= check_box_tag "company[market_attributes][]",, %>
      <%= label_tag :market_ids, -%>
      <span style="align: right;"><%= text_field_tag "emaildistro[#
{}]" %></span>
  <% end %>
  <input type="submit" value="Update Markets" onclick="'/
markets/create', {method: 'post' ,title: 'Sending status', params:
Form.serialize('marketform') }); return false;" />
<% end %>


company = Contactcompany.find(params[:company][:companyid])
  markets = params[:company][:market_attributes] ||= []
  company.market_ids = markets
    distro = params[:emaildistro]["#{}"]
    mail.update_attributes(:emaildistro => distro)

Is there a way to retrieve the emails just like the checkboxes do when
you pull up the view?
This topic is locked and can not be replied to.