【问题标题】:Rails custom routesRails 自定义路线
【发布时间】:2017-11-18 20:45:41
【问题描述】:

我在我的 Groups 控制器中创建了一个名为“add”的额外路由。

get 'groups/add', to: 'groups#add'

我的目标是拥有以下链接http://localhost:3000/groups/4/add

我想过做这个嵌套路由

resources :groups do
  get 'groups/add', to: 'groups#add'
end

但是,当我运行 rake 路由时,它没有列出。我以前从未真正使用过“自定义”路线。我通常使用脚手架生成的那些。我怎样才能做到这一点?

【问题讨论】:

    标签: ruby-on-rails nested-routes


    【解决方案1】:

    以下嵌套路由解决了我的问题:

    resources :groups do
      get 'add', on: :member
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多