Undefined method update_attributes?

醉酒当歌 提交于 2019-12-13 06:07:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!