Question

What's the problem here?:

get 'cars/index'                             <- works
get 'carsBLAH/index'                         <- Breaks!
get 'cars'        to: 'cars#index'           <- works

I assume it's some kind of rails magic / sugar, but I can't find anything about this type of situation.

Thanks!

Was it helpful?

Solution

When you define:

get 'carsBLAH/index'

By default Rails looks for index action within CarsBLAHsController. It would break if:

  1. CarsBLAHsController is not defined.
  2. CarsBLAHsController exists but index method is not defined.

You could specify the controller and action to execute for a route with:

# executes CarsController#index
get 'carsBLAH/index', to: 'cars#index'

Suggest reading Rails Routing from the Outside In for details.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top