2012-11-17 130 views
3

我在我的主页上显示4张图片,当用户点击其中一个图片时,我想更改一个参数:在我的数据库中询问。rails link_to控制器动作

在我看来,我已经添加

<%= 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. 
+0

中的验证失败告诉我,有更多的应用程序似乎比 - 是什么原因造成的AUTH控制器被打? –

回答

6

也许它不能识别链接。我想friends.picture是图像的链接,这样你就可以试试这个:

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