On Aug 14, 2011, at 5:31 PM, Michael Baldock wrote:

Walter, thanks for helping,


"Try doing it without any special effort in the controller."

Not sure what you mean I should do, I understand what you're saying, but
I'm not sure what the 'normal' / simple way to do this is.

This is what I've got in the controller after trying to simplify like
you said:

def multi_params_edit

   @events = Event.find( params[:is_ten_event_ids] )
   logger.debug("MULTI PARAMS EDIT : " + @events.length.to_s)

   @events.each  do |e|
       logger.debug("trying to make event is_ten_event = true")
       e.update_attribute(:is_ten_event, true)
   end

     redirect_to (:action =>:index)

   end


but this does what I was trying to avoid, and when I uncheck the box and
submit, the attribute is not changed. the check returns! Could you
possibly explain how I should do this in a little more detail please.

It sounds like you're inside a different controller than the EventsController. Is that true?

Could you set this up with nested attributes?

class Foo
  has_many :events
  accepts_nested_attributes_for :events
end

class Event
  belongs_to :foo
end

#FooController

def update
  @foo = Foo.find(params[:id])
  if @foo.update_attributes(params[:foo])
    redirect_to @foo, :notice => 'Yay'
  else
    render :action => :edit
  end
end

foos/edit.html.erb

<%= form_for @foo do |f| %>
... regular Foo fields here ...
<%= f.fields_for :events do |builder| %>
<%= render "event_fields", :f => builder %>
<% end %>
... rest of the form, including the submit ...
<% end %>

foos/_event_fields.html.erb

... any other Event fields ...
<%= f.check_box :is_ten_event %>

Now Foo can have as many Events as it needs, and each Event can have an is_ten_event checkbox with the magical un-check ability, and the controller can take care of everything in one submit, with no extra effort.

Unless I'm completely missing the point of your domain model, this should Just Work™.

Walter

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