mapper.rb:143:in `default_controller_and_action': missing :action (ArgumentError)

I'm trying out Rails 3 for a small web project we need done at work. After spending more time than I wanted yesterday getting everything configured correctly on my Mac (namely mysql 64 bit), I was finally ready to start generating some MVC action. I followed the steps on the http://guides.rails.info/getting_started.html Rails 3 intro page to generate a controller for my home index. This added a route to my routes.rb,

get "home/index"

I thought I'd get fancy also add a root controller and view for my website, so I coped that and slightly modified it to

root :to => "home/index"

Cool. Next, I went ahead and tried to generate a new scaffold for my first model, but uh oh, there was a problem!

/Library/Ruby/Gems/1.8/gems/actionpack-3.0.0.beta4/lib/action_dispatch/routing/mapper.rb:143:in `default_controller_and_action': missing :action (ArgumentError)
...
from /Users/.../Code/.../config/routes.rb:2
...
from /Library/Ruby/Gems/1.8/gems/railties-3.0.0.beta4/lib/rails/commands.rb:16
from script/rails:6:in `require'
from script/rails:6


My first reaction was, "!@# yet another problem with Rails 3 and my system," but after some searching for the error turned up nothing, I decided that I had probably screwed something up. Looking a little more closely at the stack trace of the error, I identified that the scaffold generation was in part based on code from my own app and not just the rails gems. Hmm, probabilities rising that I'm the culprit.

The error says that the default controller is missing an action. I checked out the gem, mapper.rb, and saw that it's parsing out some variable named "to" for a controller and action. I then opened up my routes.rb and saw that line of copied code, root :to => "home/index". I then thought back to the new rails syntax that I'd learned in the video tutorials and immediately realized my folly. One quick change,

root :to => "home#index"

and the generator is back to working. Although it can definitely be a pain dealing with open source software, it certainly is nice to be able to see the source of your problems.

Comments

Anonymous said…
THX!!! Saved a lot of time...
Andrew said…
That saved me a bunch of headaches. Thanks.
Anonymous said…
Thank you so much!!! I would never have found that!!!
Bryant Hankins said…
Thanks for posting this! Saved me a ton of time when I got this error!
toast said…
as above - thx for this
Anonymous said…
THANKS!!!!
Anonymous said…
Thank you very much!!!
Anonymous said…
Brilliant, thank you!
Anonymous said…
thx!!! saved my evening
Anonymous said…
They say 'Google is your friend' and it's true - because Google helped me find this. However, YOU provided the info. Google just indexed it.

THANKS FOR SAVING ME SO MUCH TIME!
Anonymous said…
I love you.
Anonymous said…
Thanks so much! So simple....
Anonymous said…
Great help to me..Thanx!!
Anonymous said…
Thank!
Anonymous said…
Problem solved in 20 sec... Thanks !
Anonymous said…
If only every problem were that simple to solve! Thanks!
Anonymous said…
Wish I had found this last week. Problem solved and made multiple attempts and countless hours debugging seem stupid. But thanks for the help, you have no idea how happy I am right now...
Anonymous said…
Thanks man now it happened to me also but found the solution here thanks again
Anonymous said…
Thanks, you nailed it! Exact same problem and resolution.
Anonymous said…
finally a solution! thank jebus its is not a rails problem!! thank you sir

Recent posts