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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community 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]", @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?
This topic is locked and can not be replied to.