par*_*rov 3 action controller ruby-on-rails link-to
我在我的主页上显示了4张图片,当用户点击其中一张图片时,我想更改一个参数:在我的数据库中询问.
在我看来,我补充道
<%= link_to image_tag(friends.picture), {:controller => "static_pages", :action => "recomend", :id => friends.user_id} %>
Run Code Online (Sandbox Code Playgroud)
在我有的Static_Pages_Controller中
def recomend
a = Friends.find_by_user_id(params[:id])
a.update_attribute(:asked, true)
end
Run Code Online (Sandbox Code Playgroud)
并在routes.rb
resources :static_pages do
resources :recomend
end
Run Code Online (Sandbox Code Playgroud)
但当我点击它时,服务器刷新我的家(为什么?!)并在我看到的服务器日志中
Started GET "/auth/failure?action=recomend&controller=static_pages&id=101" for 127.0.0.1 at 2012-11-17 19:59:25 +0100.
Run Code Online (Sandbox Code Playgroud)
也许它无法识别链接.我想friends.picture
是一个图像链接,所以你可以尝试这个:
<%= link_to( "", :controller => "static_pages", :action => "recomend", :id => friends.user_id) do %>
<%= image_path(friends.picture) %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
14566 次 |
最近记录: |