I just started learning Ruby on Rails and got stamped on Chapter 7 of Beginning Rails 4 Third Edition Page 151.
I generated controller as follows; $rails generate controller ControllerName [actions] [options]. This one worked OK but when I tried to generate a controller for the Users
$rails generate controller Users. I got the following error message. /routing/mapper.rb:328:in check_part : Missing :controller key on routes definition, please check your routes. (ArgumentError).
This is what my routes look like
Rails.application.routes.draw do
get 'controller_name/[actions]'
get 'controller_name/[options]
root :to => "articles#index"
resources :articles
root :to => 'users#show'
end**
I added the last route (root :to => 'users#show')
Stackoverflow community is great. I have been getting a lot of help from the archives.
Thanks
The main problem is that you need #
instead of /
in your routes.
Another problem you have is that root
tells your app where to send users when they arrive at the homepage, ie, the root directory of your app. Therefore, you can only specify one action for the root.
Instead of:
Rails.application.routes.draw do
get 'controller_name/[actions]'
get 'controller_name/[options]
root :to => "articles#index"
resources :articles
root :to => "users#show"
end
Do this:
Rails.application.routes.draw do
root :to => "articles#index"
# Or
root :to => "users#show"
get 'controller_name#[actions]'
get 'controller_name#[options]
resources :articles
end
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