【问题标题】:scope accessible rails 3.1范围可访问的导轨 3.1
【发布时间】:2012-01-18 16:19:16
【问题描述】:

我有这个范围:

scope ":user_id", :as => "user" do 
 resources :boards,  :controller => 'users/boards'
end

我知道这条路线:

http://localhost/hyperrjas/boards/

我想要一个没有 boards 的网址,然后在 routes.rb 上添加:

scope ":user_id", :as => "user" do 
 resources :boards,  :controller => 'users/boards', :path => '/'
end

效果很好,但仍然可以通过“/boards”访问...我该如何防止这种情况发生? (我使用的是 Rails 3.1)

【问题讨论】:

  • 您是否尝试将 :except => [:index] 添加到资源行的末尾?

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


【解决方案1】:

你不应该在使用资源时指定控制器名称,在这种情况下我会使用嵌套资源:

resource :user, only: :show do
  resources :boards
end

这应该为您提供以下信息:

  • /:user_id
  • /:user_id/boards
  • /:user_id/boards/new
  • /:user_id/boards/:id/
  • /:user_id/boards/:id/edit

当然还有你的宁静路线!

【讨论】:

    猜你喜欢
    • 2023-03-07
    • 2014-03-11
    • 2012-01-18
    • 2016-07-12
    • 1970-01-01
    • 2017-05-21
    • 1970-01-01
    • 2016-05-19
    • 2012-02-06
    相关资源
    最近更新 更多