【问题标题】:Custom route on Post with form. Rails 3.2.x使用表单发布自定义路线。导轨 3.2.x
【发布时间】:2013-01-06 11:12:06
【问题描述】:

刚刚浏览了stackoverflow,没能找到以下问题的解决方案:

我有一个脚手架模型 fleets,我想将路由 \fleets\postponed?id=31\ 与控制器中的特定操作相匹配 => def postponedPOST 方法。

虽然我尝试遵循一些教程,但这里失败了:

Couldn't find Fleet with id=postpone

这是我的路线:

匹配 'fleets/postponed.id?:id', :controller => "fleets", :action => "postponed", :via => :post 资源:舰队

这是POST方法的表格:

 <%= form_for @fleet, :html => { :class => 'form-horizontal' }, :url => { :id => @fleet.id }  do |f| %>
   blah-blah-blah
 <%= f.submit 'Postpone' %>
 <% end %>

下面是动作:

def 推迟 @fleet = Fleet.find(参数[:id]) @fleet.update_attributes(params[:fleet]) 结尾

任何帮助将不胜感激

【问题讨论】:

    标签: ruby-on-rails routing routes


    【解决方案1】:

    我想你只会在你的路线中想要这个

    match 'fleets/postponed', :id => /d+/, :via => :post, :controller => 'fleets', :action => 'postponed'
    

    【讨论】:

      【解决方案2】:

      要实现这条路线&lt;host&gt;/fleets/postponed?id=31,你应该有以下路线

      match 'fleets/postponed/:id', :via => :post
      

      请参阅The Query Strings 上的路由指南部分

      match ':controller/:action/:id'
      

      /fleets/postponed/1?user_id=2 的传入路径将被调度到队列控制器的延迟操作。参数将是{ :controller =&gt; “fleets”, :action =&gt; “postponed”, :id =&gt; “1”, :user_id =&gt; “2” }

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-08-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-07-25
        相关资源
        最近更新 更多