简体   繁体   English

rails link_to控制器动作

[英]rails link_to controller action

I show in my homepage 4 pictures, and when a user click on one of it, I want to change a parameter :asked in my db. 我在我的主页上显示了4张图片,当用户点击其中一张图片时,我想更改一个参数:在我的数据库中询问。

In my view I've added 在我看来,我补充道

<%= link_to image_tag(friends.picture), {:controller => "static_pages", :action => "recomend", :id => friends.user_id} %>

In the Static_Pages_Controller I have 在我有的Static_Pages_Controller中

def recomend
  a = Friends.find_by_user_id(params[:id])
  a.update_attribute(:asked, true)
end

And in routes.rb 并在routes.rb

resources :static_pages do
 resources :recomend
end

but when I click on it, the server refresh my home (why?!) and in the server logs i see 但当我点击它时,服务器刷新我的家(为什么?!)并在我看到的服务器日志中

Started GET "/auth/failure?action=recomend&controller=static_pages&id=101" for 127.0.0.1 at 2012-11-17 19:59:25 +0100.

Maybe it's not recognize the link. 也许它无法识别链接。 I suppose friends.picture is a link for image, so you can try this: 我想friends.picture是一个图像链接,所以你可以试试这个:

<%= link_to( "", :controller => "static_pages", :action => "recomend", :id => friends.user_id) do %>
  <%= image_path(friends.picture) %>
<% end %>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM