私はRuby on Rails 3.0.7を使用していますが、私のルータを正しく(そして可能な限り)設定しようとしています。 routes.rb
ファイルでリソースと同じ名前の名前空間で動作するルータを改善するには
私が持っている:
namespace :articles do
resources :categories
end
resources :articles
、期待通りに動作するためにI 必見状態resources :articles
文の前namespace
ルータのインターセプト要求するようにとに関連した名前空間にこれらを指示記事。それは上記のコードから可能な控除があるとして、それ以外の記事名前空間は「ほとんど」に達していないとなるよう
<my_site>/articles/1
<my_site>/articles/new
<my_site>/articles/1/edit
...
などのすべての要求が傍受されている、(resources :articles
場合namespace
の前に記載されています)。たとえば、あなたが<my_site>/articles/categories
のような要求を行う場合には、次のようなエラーが生成されます。
ActiveRecord::RecordNotFound
Couldn't find Article with ID=categories
だから、どのように私はこのような状況を扱うことができるとどのように私は、ルータコードを向上させることができますか?何について助言していますか?(それは注文されたように)私はこれを取得、私のコンソールでコマンドを実行するrake routes
:
articles_categories GET /articles/categories(.:format)
{:action=>"index", :controller=>"articles/categories"}
POST /articles/categories(.:format)
{:action=>"create", :controller=>"articles/categories"}
new_articles_category GET /articles/categories/new(.:format)
{:action=>"new", :controller=>"articles/categories"}
edit_articles_category GET /articles/categories/:id/edit(.:format)
{:action=>"edit", :controller=>"articles/categories"}
articles_category GET /articles/categories/:id(.:format)
{:action=>"show", :controller=>"articles/categories"}
PUT /articles/categories/:id(.:format)
{:action=>"update", :controller=>"articles/categories"}
DELETE /articles/categories/:id(.:format)
{:action=>"destroy", :controller=>"articles/categories"}
articles GET /articles(.:format)
{:action=>"index", :controller=>"articles"}
POST /articles(.:format)
{:action=>"create", :controller=>"articles"}
new_article GET /articles/new(.:format)
{:action=>"new", :controller=>"articles"}
edit_article GET /articles/:id/edit(.:format)
{:action=>"edit", :controller=>"articles"}
article GET /articles/:id(.:format)
{:action=>"show", :controller=>"articles"}
PUT /articles/:id(.:format)
{:action=>"update", :controller=>"articles"}
DELETE /articles/:id(.:format)
{:action=>"destroy", :controller=>"articles"}
あなたのレーキルートは何と言いますか? – felix
@Felix - 質問を更新しました。 – Backo