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.

35 comments:

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

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

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

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

    ReplyDelete
  5. Thank you very much!!!

    ReplyDelete
  6. Brilliant, thank you!

    ReplyDelete
  7. thx!!! saved my evening

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

    THANKS FOR SAVING ME SO MUCH TIME!

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

    ReplyDelete
  10. Great help to me..Thanx!!

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

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

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

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

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

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

    ReplyDelete
  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 :)

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

    ReplyDelete
  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

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

    ReplyDelete
  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

    ReplyDelete
  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

    ReplyDelete