问题
Im trying to allow the user to update the attributes for a single column for multiple elements based on a drop down (with name="status
) but i keep getting back the error: undefined method 'update_attributes'
. Any suggestions?
def supdate
@input_messages = InputMessage.find(params[:message_ids])
respond_to do |format|
if @input_messages.update_attributes(:status => params[:status])
format/html { redirect_to :action => "show" }
end
end
end
回答1:
Assuming that your params[:message_ids]
value is an array, then @input_messages
will be an array of results instead of a single ActiveRecord object. You may need to do something like this instead:
@input_messages.each do |input_message|
input_message.update_attributes(:status => params[:status])
end
来源:https://stackoverflow.com/questions/7230461/undefined-method-update-attributes