Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql Rails 3应用程序抛出“;未定义的方法“更新属性'&引用;保存_Mysql_Ruby On Rails_Ruby On Rails 3 - Fatal编程技术网

Mysql Rails 3应用程序抛出“;未定义的方法“更新属性'&引用;保存

Mysql Rails 3应用程序抛出“;未定义的方法“更新属性'&引用;保存,mysql,ruby-on-rails,ruby-on-rails-3,Mysql,Ruby On Rails,Ruby On Rails 3,在我的控制器里,一大堆数字都被压缩了。百分比乘以100,因此可以存储为整数 tot = @mot[1] + @mot[2] + @mot[3] exec_pct = @mot[3] / tot * 100 tact_pct = @mot[2] / tot * 100 strat_pct = @mot[1] / tot * 100 然后,应将这些值写入用户记录,如下所示: @user = User.where(id = current_user.id) @user.update_attribut

在我的控制器里,一大堆数字都被压缩了。百分比乘以100,因此可以存储为整数

tot = @mot[1] + @mot[2] + @mot[3]
exec_pct = @mot[3] / tot * 100
tact_pct = @mot[2] / tot * 100
strat_pct = @mot[1] / tot * 100
然后,应将这些值写入用户记录,如下所示:

@user = User.where(id = current_user.id)
@user.update_attributes(:strat_pct => strat_pct.to_i, :tact_pct => tact_pct.to_i, :exec_pct => exec_pct.to_i )
我收到以下错误消息:

undefined method `update_attributes'
谢谢您的帮助。

您的问题在这里:

@user = User.where(id = current_user.id)
在上面的例子中,您正在将变量id赋值给current_user.id的值,这在本例中不是您的意图

如果您这样做:

p @user.class 
然后它将返回类

您需要:

@user = User.find(current_user.id)
或:

尽管基于您的代码,但当前的_用户可能是user的一个实例。我想说,您不需要再打任何电话,您应该能够:

current_user.update_attributes(:strat_pct => strat_pct.to_i, :tact_pct => tact_pct.to_i, :exec_pct => exec_pct.to_i )
你的问题在这里:

@user = User.where(id = current_user.id)
在上面的例子中,您正在将变量id赋值给current_user.id的值,这在本例中不是您的意图

如果您这样做:

p @user.class 
然后它将返回类

您需要:

@user = User.find(current_user.id)
或:

尽管基于您的代码,但当前的_用户可能是user的一个实例。我想说,您不需要再打任何电话,您应该能够:

current_user.update_attributes(:strat_pct => strat_pct.to_i, :tact_pct => tact_pct.to_i, :exec_pct => exec_pct.to_i )

另外,我建议您从控制器中删除这些操作,并将它们放在用户模型的回调方法中。(例如,在_save之前)我建议您从控制器中删除这些操作,并将它们放在用户模型的回调方法中。(例如,在保存之前)