【问题标题】:Migrating Routes to Rails 4将路线迁移到 Rails 4
【发布时间】:2014-06-09 12:46:08
【问题描述】:

我即将将我的 rails 3 应用程序迁移到 rails 4。

我的资源中有一些额外的路线会造成一些问题。 我在路由文件中收到有关此行的错误消息:

resources :teams do
...   
   get 'apply' => 'teams#apply_membership', as: :apply_membership
   post 'apply' => 'teams#apply_membership_save', as: :apply_membership
...

这是生成的错误信息

You may have defined two routes with the same name using the `:as` option, or you may be overriding a route already defined by a resource with the same naming. For the latter, you can restrict the routes created with `resources` as explained here: 
http://guides.rubyonrails.org/routing.html#restricting-the-routes-created

在 rails3 中,可以使用相同的别名定义 get 和 post 路由并将它们路由到不同的控制器方法。

我也可以在 rails4 中执行此操作吗? 如果是,它在我的路由文件中应该是什么样子?

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-4 routes


    【解决方案1】:

    你不能取两条同名的路线。但你已经做到了。所以请改变,

    get 'apply' => 'teams#apply_membership', as: :apply_membership
    post 'apply' => 'teams#apply_membership_save', as: :update_membership
    

    在此处查看轨道路线。 http://guides.rubyonrails.org/routing.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-27
      • 2014-10-30
      • 1970-01-01
      • 2010-12-23
      • 2017-10-08
      • 1970-01-01
      • 1970-01-01
      • 2014-02-28
      相关资源
      最近更新 更多