未定义的方法update_attributes? [英] Undefined method update_attributes?

查看:131
本文介绍了未定义的方法update_attributes?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试允许用户基于下拉列表(使用name="status)来更新单个元素的多个元素的属性,但是我一直在找回错误:undefined method 'update_attributes'.有什么建议吗?

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

推荐答案

假定您的params[:message_ids]值是一个数组,那么@input_messages将是一个结果数组,而不是单个ActiveRecord对象.您可能需要执行以下操作:

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

这篇关于未定义的方法update_attributes?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆