2011-01-30 16 views
0

私は私のルートでこれを持っている:リファクタリングRailsの3つのルート

get '/boutique/new' => 'stores#new', :as => :new_store, :constraints => { :id => /[a-z0-9_-]/ } 
post '/boutique' => 'stores#create', :as => :create_store, :constraints => { :id => /[a-z0-9_-]/ } 
get '/:shortname' => 'stores#show', :as => :store, :constraints => { :id => /[a-z0-9_-]/ } 
get '/:shortname/edit' => 'stores#edit', :as => :edit_store, :constraints => { :id => /[a-z0-9_-]/ } 
put '/:shortname' => 'stores#update', :as => :update_store, :constraints => { :id => /[a-z0-9_-]/ } 
delete '/:shortname' => 'stores#delete', :as => :destroy_store, :constraints => { :id => /[a-z0-9_-]/ } 

は同じことを行うにはクリーンな方法はありますか?私はそれにいくつかのコントロール/アクションを追加すれば、それはどんなにエレガントでなくても見えません。

ありがとうございます。

答えて

2

あなたの最善の選択肢はthe standard resource routesです。あなたが構築しているアプリケーションで他の誰かが作業する必要がある場合は、感謝します。

controller :stores do 
    constraints :id => /[a-z0-9_-]/ do 
    get '/boutique/new' => :new, :as => :new_store 
    post '/boutique'  => :create, :as => :create_store 
    get '/:shortname'  => :show, :as => :store 
    get '/:shortname/edit' => :edit, :as => :edit_store 
    put '/:shortname'  => :update, :as => :update_store 
    delete '/:shortname'  => :delete, :as => :destroy_store 
    end 
end 

が、私は実際にそれをテストしていませんが、それは正常に動作する必要があります:あなたは本当に(何らかの理由で)このルーティング設定が必要な場合は、以下を試してみてください、と述べ

関連する問題