Thanks. Somewhat edited, it basically looks like this.

MODEL:

class Cpicture < ActiveRecord::Base
  belongs_to :historicsite
  has_many :tags, :dependent => :destroy
  accepts_nested_attributes_for :tags, :allow_destroy => true,
  :reject_if => proc { |attrs| attrs.all? { |k, v|
v.blank? }}
end


VIEW: part of edit.html.erb
<% cpform.fields_for :tags do |tag_form| %>
        <%= tag_form.select('tag', 'tag_group', [["value_1","value1"],
["value_2","value2"], ["value_3","value3"]]) %>
        <%= tag_form.select('tag', 'tag_name', [["value_1","value1"],
["value_2","value2"], ["value_3","value3"]]) %>

        <% unless tag_form.object.nil? || tag_form.object.new_record? %>
                  <%= tag_form.label '_delete', 'Remove:' %>
              <%= tag_form.check_box '_delete' %>
        <% end %>
<% end %>

CONTROLLER:

  def edit
    @cpicture = Cpicture.find(params[:id])
    2.times {[email protected]}
  end

  def update
    @cpicture = Cpicture.find(params[:id])
    if @cpicture.update_attributes(params[:cpicture])
      flash[:notice] = 'Cpicture was successfully updated.'
      redirect_to :action => 'show', :id => @cpicture
    else
      render :action => 'edit'
    end
  end



On Jun 1, 1:53 pm, nodoubtarockstar <[email protected]>
wrote:
> Can you possibly post some sample code so that we can see how your
> select lists are defined and how your controller is attaching the
> categories to your object? It might be a fairly easy fix to point out.
>
> Cheers!
>
> On May 30, 10:37 pm, anrake <[email protected]> wrote:
>
>
>
> > I'd like to use a drop down select field to add multiple categories to
> > my model (has_many relationship) using nested forms in Rails 2.3.2.  I
> > can get it to work fine with straight text fields, but no matter what
> > I do with select elements I always end up with "undefined method
> > `merge' for #<Array:0x2246420>"
>
> > Does anyone have a working example of using nested forms with select?
>
> > Thank you
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" 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/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to