简体   繁体   English

Rails 3.2布线错误与范围

[英]Rails 3.2 routing error with scope

This problem has taken all day of mine... 这个问题困扰了我一整天。

Well; 好;

I'm just trying to put all of my administration pages inside an /admin directory and to receive them via domain/admin style only. 我只是试图将所有管理页面放在/ admin目录中,并仅通过domain / admin样式接收它们。 I've tried to make it run with this guide. 我试图使它与指南一起运行。

According to that official guide, what I'm looking for is using scope in my routes.rb file. 根据该官方指南,我正在寻找的是在我的routes.rb文件中使用scope BECAUSE, I have used named routes tones of times inside my pages. 因为,我在页面内使用了时间的命名路由音。 I do not want my program_path named route to change admin_program_path since I have 28 different usage of it. 我不希望我的名为route的program_path更改admin_program_path因为我有28种不同的用法。

So I'm supposed to use scope instead of namespace . 所以我应该使用scope而不是namespace

Issue is: I can not make scope work with my project. 问题是:我无法使scope适用于我的项目。

Here is my routes.rb 这是我的routes.rb

 scope "/admin" do

  get "access/login"
  get "access/index"

  match "access/login_attempt", to: "access#login_attempt"
  match "access/logout", to: "access#logout"

  resources :admin_users

  root to: 'programs#index'

  resources :programs
  resources :program_categories
  resources :program_subcategories

  resources :articles
  resources :pictures



  match '/kategoriler/:id' => 'program_categories#show'
  match '/kategoriler' => 'program_categories#index'
  match '/kategori/yeni' => 'program_categories#new'
  match 'program/yeni' => 'programs#new'
  match 'programlar' => 'programs#index'
  match '/progam_categories/select_category/:program_id' => 'program_categories#select_category'
  match '/program_subcategories/select_subcategory' => 'program_subcategories#select_subcategory'
  match '/program_subcategory/add_subcategory' => 'program_subcategories#add_subcategory'

  end

Here is my controller beginning : 这是我的控制器开始:

class ProgramsController < ApplicationController

Just like told here: 就像在这里告诉:

If you want to route /admin/posts to PostsController (without the Admin:: module prefix), you could use
scope "/admin" do
  resources :posts, :comments
end

As a result, what am I getting? 结果,我得到了什么?

This error message: 此错误信息:

Routing Error

uninitialized constant ProgramsController

Whichever controller I try to access, error changes that way.. Such like uninitialized constant ProgramCategoriesController , uninitialized constant ProgramSubcategoriesController etc... 无论我尝试访问哪个控制器,错误都uninitialized constant ProgramCategoriesController这种方式更改。例如uninitialized constant ProgramCategoriesControlleruninitialized constant ProgramSubcategoriesController等。

I've tried to place application_controller both inside admin folder and root of controllers directory... No way. 我试图将application_controller放置在admin文件夹和controllers目录的根目录下...没办法。

Where is my mistake here? 我的错在哪里? :( :(

Thanks in advance... 提前致谢...

Try with :module parameter: 尝试使用:module参数:

scope '/admin', :module => 'admin' do
  # ...
end

The assumption is that your controllers are in Admin module namespace, so they start with 'Admin::'. 假定您的控制器位于Admin模块名称空间中,因此它们以“ Admin ::”开头。

[EDIT] [编辑]

It is response to your problem in comments below about path conflicts. 在以下有关路径冲突的评论中,它是对您的问题的答复。 You can use :as parameter, for example: 您可以使用:as参数,例如:

scope '/admin', :module => 'admin', :as => 'admin' do
  # ...
end

You can check it with rake routes . 您可以使用rake routes进行检查。 All routes in the admin scope should now begin with 'admin_' 现在,管理范围内的所有路由都应以“ admin_”开头

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM