【问题标题】:What does scope mean in routes.rb in Ruby on Rails?Ruby on Rails 中 routes.rb 中的范围是什么意思?
【发布时间】:2017-08-22 17:07:39
【问题描述】:

在下面的代码中使用了scope(在routes.rb中):

scope 'admin' do
  get 'dashboard', to: 'administration#dashboard'
  resources 'employees'
end

何时以及为何使用scope

【问题讨论】:

标签: ruby-on-rails ruby url scope routes


【解决方案1】:

当你想为 url 添加前缀时使用它:

# adds '/dashboard
get 'dashboard', to: 'administration#dashboard'

# adds /admin/dashboard pointing to the same action
scope '/admin' do
  get 'dashboard', to: 'administration#dashboard'
end

它有更多的选择。见Rails Routing from the Outside In

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-05-28
    • 1970-01-01
    • 2011-09-09
    • 1970-01-01
    • 2013-04-08
    • 1970-01-01
    • 2011-09-09
    相关资源
    最近更新 更多