Rails link_to 控制器动作

3

我在我的主页上展示了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.

身份验证失败告诉我应用程序似乎不像表面那样简单 - 是什么导致了身份验证控制器被触发? - Leo Romanovsky
1个回答

6
也许它没有识别链接。我想friends.picture是一个图片链接,所以你可以尝试这样做:
<%= link_to( "", :controller => "static_pages", :action => "recomend", :id => friends.user_id) do %>
  <%= image_path(friends.picture) %>
<% end %>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接