2016-09-26 8 views
1

を持つことを期待しないでくださいそれが好き:足場ルートはIDの

link_to article.name, manager_articles_path(id: article.id) 

の代わりに、レール4の方法:

私はレール5つのルートがレールとして動作するように作ることができる方法を
link_to article.name, manager_articles_path(article) 

4人?

edit_article GET /articles/:id/edit(.:format) articles#edit 
    article GET /articles/:id(.:format)  articles#show 
      PATCH /articles/:id(.:format)  articles#update 
      PUT /articles/:id(.:format)  articles#update 
      DELETE /articles/:id(.:format)  articles#destroy 

ありがとうございます。レールresourceresources

routes.rbを

Rails.application.routes.draw do 
    root 'home#index' 
    resource :articles 
end 
+0

ちょっと記事の 'routes.rb'コードを表示してください。 –

+0

@ABPrimeが投稿を更新しました。 – rmagnum2002

答えて

5

同じではありません。

リソース

http://guides.rubyonrails.org/routing.html#singular-resources

は時々、あなたは、クライアントが常に がIDを参照せずに検索するリソースを持っています。たとえば、/ profileには、現在ログインしているユーザーのプロフィールを常に と表示します。この場合は、 のshow/(/ profile /:idではなく)/ profileに単一リソースを使用して表示アクションを行うことができます。

ルート

edit_articles  GET /articles/edit(.:format) articles#edit 
articles   GET /articles(.:format)   articles#show 
        PATCH /articles(.:format)   articles#update 
        PUT /articles(.:format)   articles#update 
        DELETE /articles(.:format)   articles#destroy 

リソース

リソースは任意の項目を一般的な要求を処理するための方法として使用され、その後、単数形のリソースは、現在の項目に取り組むための方法です手元に。

ルート

articles  GET /articles(.:format)   articles#index 
      POST /articles(.:format)   articles#create 
new_article GET /articles/new(.:format)  articles#new 
edit_article GET /articles/:id/edit(.:format) articles#edit 
    article GET /articles/:id(.:format)  articles#show 
      PATCH /articles/:id(.:format)  articles#update 
      PUT /articles/:id(.:format)  articles#update 
      DELETE /articles/:id(.:format)  articles#destroy 

私は、これはあなたを助けることを願っています。

+0

ああ、facepalm、one 's .. ..ありがとう。 – rmagnum2002

+0

@ rmagnum2002:それは起こります。 –