简体   繁体   English

运行rails server或rails generate后出错

[英]Error after running rails server or rails generate

I'm learning to develop a Rails application by following this book: http://ruby.railstutorial.org Currently I am at Chapter 6. 我正在学习如何按照本书开发Rails应用程序: http//ruby.railstutorial.org目前我在第6章。

It all went fine untill I wanted to check out the app using the 'rails s' command. 这一切都很顺利,直到我想使用'rails s'命令查看应用程序。 After running the command I got the following error: 运行该命令后,我收到以下错误:

'default_controller_and_action': missing :action (ArgumentError)

I had this problem earlier and solved it by correcting a mistake in 'routes.rb'. 我之前遇到过这个问题并通过纠正'routes.rb'中的错误解决了这个问题。 But I am not able to solve it this time ;( 但这次我无法解决;(

routes.rb 的routes.rb

SampleApp::Application.routes.draw do

  get "users/new"

  root to: 'static_pages#home'

  match '/signup', to: 'users#new'

  match '/home', to: 'static_pages#home'

  match '/help', to: 'static_pages#help'

  match '/about', to: 'static_pages#about'

  match '/contact', to: 'static_pages#'

end

application.html.erb application.html.erb

    <!DOCTYPE html>
    <html>
      <head>
        <title><%= full_title(yield(:title)) %></title>
        <%= stylesheet_link_tag    "application", media: "all" %>
        <%= javascript_include_tag "application" %>
        <%= csrf_meta_tags %>
        <%= render 'layouts/shim' %>

     </head>
      <body>
       <%= render 'layouts/header' %>
       <div class="container">
          <%= yield %>
          <%= render 'layouts/footer' %>
          <%= debug(params) if Rails.env.development? %>
        </div>
      </body>
    </html>

_header.html.erb _header.html.erb

    <header class="navbar navbar-fixed-top navbar-inverse">
  <div class="navbar-inner">
    <div class="container">
      <%= link_to "sample app", root_path, id: "logo" %>
      <nav>
        <ul class="nav pull-right">
          <li><%= link_to "Home",    root_path %></li>
          <li><%= link_to "Help",    help_path %></li>
          <li><%= link_to "Sign in", '#' %></li>
        </ul>
      </nav>
    </div>
  </div>
</header>

_footer.html.erb _footer.html.erb

<footer class="footer">
  <nav>
    <ul>
      <li><%= link_to "About",   about_path %></li>
      <li><%= link_to "Contact", contact_path %></li>
      <li><a href="#/">News</a></li>
    </ul>
  </nav>
</footer>

I hope that someone can help me solve this problem! 我希望有人可以帮我解决这个问题! :) :)

Thanks in advance! 提前致谢!

match '/contact', to: 'static_pages#'

is missing an action. 缺少一个动作。

It has the form 'controller#action' . 它具有'controller#action'形式。 In this case you only provided the controller, but is missing the action name. 在这种情况下,您只提供了控制器,但缺少操作名称。

If in this part of the tutorial you still haven't created an action for contact, you can either comment this line out until you create it, or create a controller for it now. 如果在本教程的这一部分中您还没有为联系人创建动作,则可以在创建它之前对此行进行注释,或者立即为其创建控制器。

In the first case, the code would be 在第一种情况下,代码将是

#   match '/contact', to: 'static_pages#'

In the second case, it would be necessary to insert 在第二种情况下,有必要插入

# app/controllers/static_pages_controller.rb
...
def contact
end

And create a layout at /app/views/static_pages/contact.html.erb 并在/app/views/static_pages/contact.html.erb创建一个布局

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM