Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Missing :controller key on routes definition, please check your routes

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

like image 809
Ashenafi Abera Avatar asked Dec 06 '22 15:12

Ashenafi Abera


1 Answers

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
like image 93
therealrodk Avatar answered Jan 20 '23 15:01

therealrodk