ruby-on-rails - rails link_to Controller Action

标签 ruby-on-rails controller action link-to

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

在我看来我已经添加了

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

最佳答案

可能无法识别链接。我想 friends.picture 是一个图片链接,所以你可以试试这个:

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

关于ruby-on-rails - rails link_to Controller Action ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13433854/

相关文章:

c# - 将 lambda 分配给 Action<T>

ruby-on-rails - 如何监控美洲狮服务器?

spring - 带注释的 Controller 的 HandlerExceptionResolver

mysql - rake 数据库 :schema:dump is not producing schema for all databases

unit-testing - 单元测试Grails Controller

php - Controller 没有容器集,是不是忘记定义为服务订阅者了

swift - 处理两种文档类型

html - 重定向选择框中的选择选项

ruby-on-rails - 如何为亚马逊 s3 图像添加过期标题?

ruby-on-rails - 我如何使用路由别名改进重定向