【问题标题】:Rails 4.1 No route matches [GET] "/controller/action" on link_to :method => :putRails 4.1 没有路由匹配 [GET] "/controller/action" on link_to :method => :put
【发布时间】:2015-10-23 01:30:06
【问题描述】:

这是我的第一个 RoR 项目。

我的问题是通过一个表单传递两个不同的请求(删除和放置),所以我选择在表单中执行删除并强制 link_to 函数使用放置请求。

但每次我得到:No route matches [GET] "/examplecontrollers/exampleaction"

我不习惯 Ruby/Rails 语法,所以我尝试了以下所有这些:

<%= link_to raw('<i class="fa fa-check fa-lg"></i>'), {:action => :exampleaction, :id => obj.id}, :class => 'btn', :method => 'put'%>

<%= link_to raw('<i class="fa fa-check fa-lg"></i>'), {:action => :exampleaction, :id => obj.id}, {:class => 'btn', :method => 'put'} %>

<%= link_to raw('<i class="fa fa-check fa-lg"></i>'), examplecontrollers_exampleaction_path(:id => obj.id), {:class => 'btn', :method => 'put'} %>

<%= link_to raw('<i class="fa fa-check fa-lg"></i>'), examplecontrollers_exampleaction_path(:id => obj.id), {:class => 'btn', :method => :put} %>

<%= link_to raw('<i class="fa fa-check fa-lg"></i>'), examplecontrollers_exampleaction_path(:id => obj.id), {:class => 'btn', method: :put} %>

在我的routes.rb,我已经一一尝试了:

put 'examplecontrollers/exampleaction' => "examplecontrollers#exampleaction", :as => 'exampleaction'

或者只是

put 'examplecontrollers/exampleaction'

您能否告诉我正确的做法和/或您是否有其他方法来处理“多请求表单”。

感谢您的帮助,对不起我的英语。

【问题讨论】:

    标签: put link-to ruby-on-rails-4.1


    【解决方案1】:

    你需要像这样输入你的 route.rb

    {map.resources :examplecontrollers, :collection =>{:exampleaction=> :get} }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-06
      • 1970-01-01
      • 1970-01-01
      • 2013-03-21
      • 1970-01-01
      • 2015-12-12
      • 2012-07-17
      • 2011-12-25
      相关资源
      最近更新 更多