【问题标题】:rails link_to controller actionrails link_to 控制器动作
【发布时间】:2012-11-17 19:10:26
【问题描述】:

我在我的主页上显示了 4 张图片,当用户点击其中一张时,我想更改一个参数 :asked in my db.

在我看来我已经添加了

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

【问题讨论】:

  • 身份验证失败告诉我应用程序比看起来的要多 - 是什么导致身份验证控制器被击中?

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


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多