Why is my development server not loading? default_controller_and_action': missing :action (ArgumentError)

前端 未结 6 2053
我在风中等你
我在风中等你 2020-12-09 08:17

I\'m a Ruby nuby (and new to Stack Overflow) working on the Rails Tutorial by Michael Hartl and all of a sudden my development server won\'t load and keeps exiting. Console

相关标签:
6条回答
  • 2020-12-09 08:43

    change your default root in the routes.rb file.

    get "static_pages#home"  TO root to: 'static_pages#home'
    

    I've gone through the same issue, and the above change worked for me.

    0 讨论(0)
  • 2020-12-09 08:53

    This is caused by incorrect routes -
    Please check your config/routes.rb , even if one route mentioned is wrong then this error is thrown !!
    Also make sure that the route is

    '/url/for/something' => 'controller#action'
    

    or

    root :to => 'controller#action
    
    0 讨论(0)
  • 2020-12-09 08:54

    By default you get this:

    Rails.application.routes.draw do
      get 'static_pages/...'
    
      get 'static_pages/home'
    
      get 'static_pages/help'
    

    JUST ERASE THIS:

      get 'static_pages/...'
    

    AND YOU WILL HAVE THIS IN THE ROUTES.RB FILE

    Rails.application.routes.draw do
    
      get 'static_pages/home'
    
      get 'static_pages/help'
    
    0 讨论(0)
  • 2020-12-09 08:55

    I'm also a Ruby nuby and had the same error while working on the Rails Tutorial by Michael Hartl. If you're like me, you might be just typing in all code that appears in the book with really reading or understanding the text. Not everything is step by step. In demonstrating camel case vs. snake case Hartl shows a box with the following code

    $ rails generate controller static_pages ...
    

    Here, Hartl is simply trying to contrast instructions to generate a StaticPages controller using snake case, rather than camel case, which was done in Listing 3.4. The dots "..." are simply to edit out or truncate the rest of the instructions for the cmd line. I typed in exactly what was shown and wound up with the following in my routes file:

    SampleApp::Application.routes.draw do
     get "static_pages/..."
    
     get "static_pages/home"
    
     get "static_pages/help"
    

    open up your routes file, delete

    get "static_pages/..."
    

    save the routes file, and try starting rails server again.

    I also destroyed "rails generate controller static_pages ..." Not sure if that had any effect, but now everything works.

    0 讨论(0)
  • 2020-12-09 09:02

    When I ran into this problem, it was because one of the routes in routes.rb had a slash (/) instead of the hash (#) when using the controller#action syntax (I used "controller/action", which was incorrect).

    For example, I accidentally had root :to => 'home/index'. It was supposed to be root :to => 'home#index'.

    I found this solution in here.

    0 讨论(0)
  • 2020-12-09 09:05

    In my case it was caused by the suffix slash '/' in some of my routes. E.g.

    post 'load_query/'
    

    After removing this suffix to

    post 'load_query'
    

    it worked.

    0 讨论(0)
提交回复
热议问题