Tuesday, July 27, 2010

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.


  1. THX!!! Saved a lot of time...

  2. That saved me a bunch of headaches. Thanks.

  3. Thank you so much!!! I would never have found that!!!

  4. Thanks for posting this! Saved me a ton of time when I got this error!

  5. Thank you very much!!!

  6. Brilliant, thank you!

  7. thx!!! saved my evening

  8. 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.


  9. Thanks so much! So simple....

  10. Great help to me..Thanx!!

  11. Problem solved in 20 sec... Thanks !

  12. If only every problem were that simple to solve! Thanks!

  13. 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...

  14. Thanks man now it happened to me also but found the solution here thanks again

  15. Thanks, you nailed it! Exact same problem and resolution.

  16. finally a solution! thank jebus its is not a rails problem!! thank you sir

  17. U saved my time dude..
    such a minor mistake/ but was bugging me for an hour. FInally got it resolved.
    Thank you once again :)

  18. Why is it a pain to deal with open-source software? That is an outrageous lie!

  19. The blog or and best that is extremely useful to keep I can share the ideas of the future as this is really what I was looking for, I am very comfortable and pleased to come here. Thank you very much.

    Digital Marketing Course in Chennai
    Digital Marketing Training in Chennai
    Online Digital Marketing Training
    SEO Training in Chennai

  20. It's great that people are interested in this topic.

  21. Thanks for sharing an informative blog keep rocking bring more details.I like the helpful info you provide in your articles. I’ll bookmark your weblog and check again here regularly. I am quite sure I will learn much new stuff right here! Good luck for the next!
    Artificial Intelligence Training in Chennai

    Ai Training in Chennai

    Artificial Intelligence training in Bangalore

    Ai Training in Bangalore

    Artificial Intelligence Training in Hyderabad | Certification | ai training in hyderabad

    Artificial Intelligence Online Training

    Ai Online Training

    Blue Prism Training in Chennai

  22. Thanks for sharing this wonderful content.its very useful to us.This is incredible,I feel really happy to have seen your webpage.I gained many unknown information, the way you have clearly explained is really fantastic.keep posting like this information.
    Full Stack Training in Chennai

    Full Stack Course Chennai
    Full Stack Training in Bangalore

    Full Stack Course in Bangalore

    Full Stack Training in Hyderabad

    Full Stack Course in Hyderabad

    Full Stack Training

    Full Stack Course

    Full Stack Online Training

    Full Stack Online Course

  23. I am really happy with your blog because your article is very unique and powerful for new.
    Data Science
    ETL Testing
    Python Online Classes

  24. That's really impressive and helpful information you have given, very valuable content.
    We are also into education and you also can take advantage of Selenium Training in Pune

  25. That's really impressive and helpful information you have given, very valuable content.
    We are also into education and you also can take advantage of Selenium Training in Pune

  26. That's really impressive and helpful information you have given, very valuable content.
    We are also into education and you also can take advantage really awesome job oriented courses

  27. I read your article it is very interesting and every concept is very clear, thank you so much for sharing. AWS Certification Course in Chennai

  28. Right on target with this review, I really accept that this astonishing site needs substantially more consideration. I'll presumably be getting back to peruse more, a debt of gratitude is in order for the data!best interiors