@snusnu's plugin "accepts_nested_attributes" is probably the answer
but as a noobie I'm not having any luck getting it work.
(http://github.com/snusnu/dm-accepts_nested_attributes)

Here's the scenario again:

MODELS:

class Trip
  ...
  has n, :trip_countries
  has n, :countries, :through => :trip_countries
  accepts_nested_attributes_for :countries
end

class Country
  ...
  has n, :trip_countries
  has n, :trips, :through => :trip_countries
  accepts_nested_attributes_for :trips
end

class TripCountry
  property :id, Serial
  belongs_to :trip
  belongs_to :country
end

In the trip VIEW form we have:
<% Country.all( :order=>[:name] ).each do |country| %>
  <% checked = trip.countries.include?(country) ? 'checked' : nil %>
  <%= check_box :name => "trip[countries][][id]",
      :value => country.id, :checked => checked,
      :boolean=>false, :label => country.name
  %>
<% end %>


I'm formatting the checkbox field names as "trip[countries][][id]"
but I'm not sure whether they should be
"trip[countries][]" or "trip[countries][id][]" etc?!
(See http://wonderfullyflawed.com/2009/02/17/rails-forms-microformat )
Either way the checkbox selections will not save.

Any help greatly appreciated!
Many many thanks,
George

--

You received this message because you are subscribed to the Google Groups 
"merb" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected].
For more options, visit this group at http://groups.google.com/group/merb?hl=en.


Reply via email to