`default_controller_and_action': missing :controller (ArgumentError) in Ruby 3

13,192

Solution 1

Please check if the jobs controller is still there. Because this is the first root directive in your routes declarations (and still, it does not make sense to have more than one), Rails is checking if this root route is available. It seems that the jobs controller is missing and causing this error.

Solution 2

I think you still have a route in routes.rb which in invalid. Please recheck all the routes, corresponding controller and action. Please also share the full error trace, that way we can pin-point the issue.

Solution 3

At first, check Rails routing documentation. I think you are getting this error because you are unable to define route file. The problem I figure out in your route file are :-

a. You have three different root in your route file.

root :to => "jobs#index"
root :to => 'home/index'
 root :to => "sessions#login"

b. You are defining same routes multiple times.

 get "sessions/login,"
 get "sessions/home,"
 get "sessions/profile,"
 get "sessions/setting"
 get "users/new"

match "signup", :to => "users#new"
match "login", :to => "sessions#login"
match "home", :to => "sessions#home"
match "profile", :to => "sessions#profile"
match "setting", :to => "sessions#setting"

The solution might be as follows :-

a. Fix the root path at first. Which path you want to make root whether it is jobs index or home index or sessions login.

b. I think you are trying to define your routes as such

match "signup", :to => "users#new", via: :get
match "login", :to => "sessions#login", via: :get
match "home", :to => "sessions#home", via: :get
match "profile", :to => "sessions#profile", via: :get
match "setting", :to => "sessions#setting", via: :get
Share:
13,192

Related videos on Youtube

Awhitey98
Author by

Awhitey98

I currently work at Mobi Wireless as a Software Developer on the Custom Solutions Team located in Indianapolis, In. I received my Computer information management certificate from Ashworth College. I have been working with Ruby on Rails for a little over a year now. I started off learning on my own and then received a Jr. Developer roll at my company, since I have moved up to a Software Developer roll with Mobi Wiress Custom Solutions team.

Updated on June 04, 2022

Comments

  • Awhitey98
    Awhitey98 almost 2 years

    I am creating a website were users can post jobs and users can login,register etc. I have created my jobs model and created my user model for the login/register part. When I try to load rails server I keep getting this error below and cannot figure out what I'm doing wrong or how to fix. I originally was trying to use devise and create the users model but was having issues so I deleted the files for it. I am wondering if I deleted something or if I am missing something in my routes.rb file. Can someone help or point me in the right direction? I will post my routes.rb file as well. Thanks for any guidance as I am still new to rails. The only thing I added to the routes.rb file was root :to => "sessions#login" and below that. Im sure other info in this was added when i created the models and controller.

    /home/whitey7/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.8/lib/action_dispatch/routing/mapper.rb:181:in `default_controller_and_action': missing :controller (ArgumentError)**

    Routes.rb

    Application.routes.draw do 
     get "sessions/login,"
     get "sessions/home,"
     get "sessions/profile,"
     get "sessions/setting"
     get "users/new"
    
     resources :jobs 
    
    
    
    root :to => "jobs#index"
    root :to => 'home/index'
     root :to => "sessions#login"
    match "signup", :to => "users#new"
    match "login", :to => "sessions#login"
    match "logout", :to => "sessions#logout"
    match "home", :to => "sessions#home"
    match "profile", :to => "sessions#profile"
    match "setting", :to => "sessions#setting"
    
    • suhovius
      suhovius over 11 years
      I just can guess that you have not some controller or action at your app. And you set this non existing controller as default route. Please provide full error trace that you have for more details, to figure out where is the source of error.
    • awenkhh
      awenkhh over 11 years
      why do you have three different root assignments? This is not working ... remove two of them and check again
  • Awhitey98
    Awhitey98 over 11 years
    Thanks for the info I will check and see if the job controller is still there. I thought i did check that maybe I didnt. Also When I initally set up the jobs model and it set the roots route up. I was following a tutorial for the users model that I found and it had me add another root assignment. I Guess i didnt realize it wasn't needed and only one assignment was.