I want to create a model in rails:
rails generate model ABCThing
So this will create a table, abc_things
. Great. The problem comes with the controller and routing. I want my controller to be:
class ABCThingsController < ApplicationController
end
However, after adding in the routes.rb
resources :abc_things, :only => [:index]
and creating the corresponding index
view, i get the following error in the browser:
Expected /app/controllers/abc_things_controller.rb to define AbcThingsController
The problem is easy to see ("ABCThings".tableize.classify => "AbcThing"
), but i'm not so sure how to fix it. I want to override rails default routing from the view to the controller, but am not sure how.
Would appreciate any help (and suggestions for a better question title!)
I had this issue and after trying all of the above solutions; was able to fix my problem using the inflector.
In my case the issue was that TLA::ThingsController
was being resolved as Tla::ThingsController
putting the following in my initializers folder fixed it
config/initializers/inflections.rb
ActiveSupport::Inflector.inflections do |inflect|
inflect.acronym 'TLA'
end
You should set custom controller name, in routes.rb:
resources :abc_things, :only => [:index], :controller => "ABCThings"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With