Railsルートの詳細を理解しようとしています。Railsルート:入れ子、メンバー、コレクション、名前空間、スコープおよびカスタマイズ可能
メンバーとコレクション
# Example resource route with options:
resources :products do
member do
get 'short'
post 'toggle'
end
collection do
get 'sold'
end
end
名前空間と範囲
# Example resource route within a namespace:
namespace :admin do
resources :products
end
scope :admin do
resources :products
end
制約、
# Example resource route with options:
get "/questions", to: redirect {|params, req|
begin
id = req.params[:category_id]
cat = Category.find(id)
"/abc/#{cat.slug}"
rescue
"/questions"
end
}
Redirect_to
カスタマイズ:
resources :profiles
編集用resource profiles
から元のURL。
http://localhost:3000/profiles/1/edit
私はクリックするだけedit profile
を通して利用可能なユーザーのためにそれを作り、以下のようにURLを見てみたいです。
http://localhost:3000/profile/edit
また、ほとんどの大企業は、レールに彼らのルートを設計どのように高度なルーティングは、ありますか?新しいルートがあれば、本当にうれしいでしょう。
ありがとうございました!
私は 'resource:questions'を持っていますが、' constraints:{subdomain: 'blog'} 'と' resource:posts'もあります。今、私がサブドメインのブログに行くとき、私はまだ質問を見ることができます。あなたは質問のためのアクセスを与えないようにブロックする – 7urkm3n