简体   繁体   中英

How do I refactor these Rails routes?

I have the following routes. I want the structure of the app to remain the same (one controller with multiple functions), but I want to make the routes file look more reasonable and easily extensible.

get 'splunk/ocd/:order_id' => "splunk#order_collection_details"
get 'splunk/ord/:order_id' => "splunk#order_request_details"
get 'splunk/ord_ar/:request_id' => "splunk#ord_associated_requests"
get 'splunk/ord_ad/:user_id/:deal_option_id' => "splunk#ord_additional_details"
get 'splunk/avatax_logs/:order_id' => "splunk#avatax_logs"
get 'splunk/billing_updates/:billing_record_id' => "splunk#billing_updates"
get 'splunk/cc_storage_details/:billing_record_id' => "splunk#cc_storage_details"

I agree with @MikeBrant that there doesn't really seem to be any huge need to refactor this, but if you really wanted to, I might try something like this -

controller :splunk do
  get 'splunk/ocd/:order_id' => :order_collection_details
  get 'splunk/ord/:order_id' => :order_request_details
  get 'splunk/ord_ar/:request_id' => :ord_associated_requests
  get 'splunk/ord_ad/:user_id/:deal_option_id' => :ord_additional_details
  get 'splunk/avatax_logs/:order_id' => :avatax_logs
  get 'splunk/billing_updates/:billing_record_id' => :billing_updates
  get 'splunk/cc_storage_details/:billing_record_id' => :cc_storage_details
end

It's a little more organized and easier to read, but if your whole app is going to be around one controller, I'm not sure I see the need.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM