Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/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
Ruby on rails 由link_to调用的函数,即使在硬编码时也不起作用_Ruby On Rails_Ruby_Ruby On Rails 3 - Fatal编程技术网

Ruby on rails 由link_to调用的函数,即使在硬编码时也不起作用

Ruby on rails 由link_to调用的函数,即使在硬编码时也不起作用,ruby-on-rails,ruby,ruby-on-rails-3,Ruby On Rails,Ruby,Ruby On Rails 3,出于某种原因,在我的函数make_feed_preference中,@user.feed_preference从不更改,即使我将其硬编码为@user.feed_preference=foobar,但看起来将_重定向到“posts”效果不错 错误在于,即使在按下链接之后,feed_首选项始终为nil,因此if feed_首选项==nil始终为真。我还是不知道是什么原因造成的 make_feed_首选项存储在users_控制器中。它所做的是显示一个新闻提要,但根据偏好值排序,例如时间、趋势值、关注者

出于某种原因,在我的函数make_feed_preference中,@user.feed_preference从不更改,即使我将其硬编码为@user.feed_preference=foobar,但看起来将_重定向到“posts”效果不错

错误在于,即使在按下链接之后,feed_首选项始终为nil,因此if feed_首选项==nil始终为真。我还是不知道是什么原因造成的

make_feed_首选项存储在users_控制器中。它所做的是显示一个新闻提要,但根据偏好值排序,例如时间、趋势值、关注者

<%= link_to displayIcon(1), {:action => :make_feed_preference, :id => current_user.id, :preference => "trending value",  :controller => "users"}, :method => :post %>

注意:我通过向用户附加一个新类来修复它。

我将在这里使用一个条件:

redirect_to '/posts', :notice => if @user.save
    'You have updated your feed preference.'
else
    'Your input was invalid.'
end

您会发现@user验证可能失败。

Jon,您可以添加您的解决方案作为答案并“接受”它吗?
redirect_to '/posts', :notice => if @user.save
    'You have updated your feed preference.'
else
    'Your input was invalid.'
end