我在我的主页上展示了4张图片,当用户点击其中一张时,我希望能够更改数据库中的一个参数: asked。
在我的视图中,我已经添加了:
<%= link_to image_tag(friends.picture), {:controller => "static_pages", :action => "recomend", :id => friends.user_id} %>
在 Static_Pages_Controller 中,我有以下内容:
def recomend
a = Friends.find_by_user_id(params[:id])
a.update_attribute(:asked, true)
end
在 routes.rb 文件中:
resources :static_pages do
resources :recomend
end
但是我点击它时,服务器刷新了我的主页(为什么?!)在服务器日志中我看到:
Started GET "/auth/failure?action=recomend&controller=static_pages&id=101" for 127.0.0.1 at 2012-11-17 19:59:25 +0100.