Reputation: 183549
I want to have a test controller where I can easily add actions and have the router automatically recognize them. I'm able to create a routes entry that matches any controller action, (EXAMPLE 1) but can't figure out how to limit it to the test controller (EXAMPLE 2).
routes.rb:
# EXAMPLE 1: Match any generic controller actions (e.g. any_controller/any_action):
get ':controller/:action
# EXAMPLE 2: Match any test controller actions (e.g. test/any_action):
get 'test/:action'
The #2 example results causes a routing error:
routing/mapper.rb:229:in `default_controller_and_action': missing :controller (ArgumentError)
Upvotes: 1
Views: 305
Reputation: 53028
You could use it as below:
get 'test/:action', controller: :test
This will create the route as below:
GET /test/:action(.:format) test#:action
This will match any test controller actions (e.g. test/any_action)
Upvotes: 3
Reputation: 11811
You should tell rails what shall happen with this route:
get ':controller/:action' => "office#show"
Upvotes: 0