2017-10-16 4 views
0

は、私が持っている:私は、次のルート与える取得部分ルート私のconfig/routes.rbをで

resources :landings do 
    collection do 
    get 'about' 
    end 
end 

about_landings GET  /landings/about(.:format)  landings#about 
landings  GET  /landings(.:format)    landings#index 
       POST /landings(.:format)    landings#create 
new_landing  GET  /landings/new(.:format)   landings#new 
edit_landing GET  /landings/:id/edit(.:format) landings#edit 
landing   GET  /landings/:id(.:format)   landings#show 
       PATCH /landings/:id(.:format)   landings#update 
       PUT  /landings/:id(.:format)   landings#update 
       DELETE /landings/:id(.:format)   landings#destroy 

を、私は唯一の可能性についてのルート、および夫婦のを必要とします他の静的ページルート。そのためのroutes.rb構文は何ですか?

答えて

1

あなたが何かを行うことができますlike:

resources :landings, only: [] do 
    collection do 
    get 'about' 
    end 
end 
あなたを与えるだろう

about_landings GET /landings/about(.:format) landings#about 

を個人的には、私はパス名(審美的)としてabout_landingsを好きではないので、私は私がすると思う:

あなたを与えるだろう
scope module: :landings do 
    get 'about' 
end 

about GET /about(.:format) landings#about 

そしてあなただけのIMOが進歩しているabout_pathを使用することができます(と、を構築しながら、少ない文字を入力しますそれによって全体の寿命に数秒を追加します)。また、ブラウザのアドレスバーにクリーナー(もう一度、IMO)URLが表示されます。

+0

はい、これは私が探しているものです。私は同意する、モジュールのルートは "クリーナー"です – EastsideDeveloper

+0

素晴らしい!あなたのために働くことを願っています。あなたが合っているようにupvote/acceptを自由に感じてください。 – jvillian

3

あなただけ

resources :landings, except: [:show, :new, :edit] do 
    collection do 
    get 'about' 
    end 
end 

OR

resources :landings, only: [:index] do 
    collection do 
    get 'about' 
    end 
end 

NOTE /除いて使用することができます:あなたが唯一の特定のaction.Iだけ与えられた例をスキップするか、許可することができ

+0

はい、これは機能します。私は、個別にリストすることなく、すべてのデフォルトルートを無効にする構文があるかどうか疑問に思っていた。 – EastsideDeveloper

関連する問題