Rails App中的路由错误

时间:2015-11-13 19:11:39

标签: html css ruby-on-rails twitter-bootstrap ruby-on-rails-4

在安装Elasticsearch(工作正常)的过程中,退出我的应用程序的功能不再有效。我收到以下错误消息。

    No route matches [GET] "/users/sign_out"

    Rails.root: C:/Users/mdavis/workspace/intakelog

    Application Trace | Framework Trace | Full Trace

    Routes match in priority from top to bottom

当我运行Rake Routes时,我看到了正确的路径。

$ rake routes
                  Prefix Verb   URI Pattern                                    C                                                                   ontroller#Action
              insurances GET    /insurances(.:format)                          i                                                                   nsurances#index
                         POST   /insurances(.:format)                          i                                                                   nsurances#create
           new_insurance GET    /insurances/new(.:format)                      i                                                                   nsurances#new
          edit_insurance GET    /insurances/:id/edit(.:format)                 i                                                                   nsurances#edit
               insurance GET    /insurances/:id(.:format)                      i                                                                   nsurances#show
                         PATCH  /insurances/:id(.:format)                      i                                                                   nsurances#update
                         PUT    /insurances/:id(.:format)                      i                                                                   nsurances#update
                         DELETE /insurances/:id(.:format)                      i                                                                   nsurances#destroy
        new_user_session GET    /users/sign_in(.:format)                       d                                                                   evise/sessions#new
            user_session POST   /users/sign_in(.:format)                       d                                                                   evise/sessions#create
    destroy_user_session DELETE /users/sign_out(.:format)                      d                                                                   evise/sessions#destroy
           user_password POST   /users/password(.:format)                      d                                                                   evise/passwords#create
       new_user_password GET    /users/password/new(.:format)                  d                                                                   evise/passwords#new
      edit_user_password GET    /users/password/edit(.:format)                 d                                                                   evise/passwords#edit
                         PATCH  /users/password(.:format)                      d                                                                   evise/passwords#update
                         PUT    /users/password(.:format)                      d                                                                   evise/passwords#update
cancel_user_registration GET    /users/cancel(.:format)                        d                                                                   evise/registrations#cancel
       user_registration POST   /users(.:format)                               d                                                                   evise/registrations#create
   new_user_registration GET    /users/sign_up(.:format)                       d                                                                   evise/registrations#new
  edit_user_registration GET    /users/edit(.:format)                          d                                                                   evise/registrations#edit
                         PATCH  /users(.:format)                               d                                                                   evise/registrations#update
                         PUT    /users(.:format)                               d                                                                   evise/registrations#update
                         DELETE /users(.:format)                               d                                                                   evise/registrations#destroy
         search_accounts GET    /accounts/search(.:format)                     a                                                                   ccounts#search
           account_notes POST   /accounts/:account_id/notes(.:format)          n                                                                   otes#create
        new_account_note GET    /accounts/:account_id/notes/new(.:format)      n                                                                   otes#new
       edit_account_note GET    /accounts/:account_id/notes/:id/edit(.:format) n                                                                   otes#edit
            account_note PATCH  /accounts/:account_id/notes/:id(.:format)      n                                                                   otes#update
                         PUT    /accounts/:account_id/notes/:id(.:format)      n                                                                   otes#update
                         DELETE /accounts/:account_id/notes/:id(.:format)      n                                                                   otes#destroy
                accounts GET    /accounts(.:format)                            a                                                                   ccounts#index
                         POST   /accounts(.:format)                            a                                                                   ccounts#create
             new_account GET    /accounts/new(.:format)                        a                                                                   ccounts#new
            edit_account GET    /accounts/:id/edit(.:format)                   a                                                                   ccounts#edit
                 account GET    /accounts/:id(.:format)                        a                                                                   ccounts#show
                         PATCH  /accounts/:id(.:format)                        a                                                                   ccounts#update
                         PUT    /accounts/:id(.:format)                        a                                                                   ccounts#update
                         DELETE /accounts/:id(.:format)                        a                                                                   ccounts#destroy
                programs GET    /programs(.:format)                            p                                                                   rograms#index
                         POST   /programs(.:format)                            p                                                                   rograms#create
             new_program GET    /programs/new(.:format)                        p                                                                   rograms#new
            edit_program GET    /programs/:id/edit(.:format)                   p                                                                   rograms#edit
                 program GET    /programs/:id(.:format)                        p                                                                   rograms#show
                         PATCH  /programs/:id(.:format)                        p                                                                   rograms#update
                         PUT    /programs/:id(.:format)                        p                                                                   rograms#update
                         DELETE /programs/:id(.:format)                        p                                                                   rograms#destroy
             pages_index GET    /pages/index(.:format)                         p                                                                   ages#index
                    root GET    /                                              p                                                                   ages#index

这是服务器日志的错误消息

ActionController::RoutingError (No route matches [GET] "/javascripts/default.js"):
  actionpack (4.1.8) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
  actionpack (4.1.8) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.1.8) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.1.8) lib/rails/rack/logger.rb:20:in `block in call'
  activesupport (4.1.8) lib/active_support/tagged_logging.rb:68:in `block in tagged'
  activesupport (4.1.8) lib/active_support/tagged_logging.rb:26:in `tagged'
  activesupport (4.1.8) lib/active_support/tagged_logging.rb:68:in `tagged'
  railties (4.1.8) lib/rails/rack/logger.rb:20:in `call'
  actionpack (4.1.8) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
  rack (1.5.2) lib/rack/runtime.rb:17:in `call'
  activesupport (4.1.8) lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call'
  rack (1.5.2) lib/rack/lock.rb:17:in `call'
  actionpack (4.1.8) lib/action_dispatch/middleware/static.rb:84:in `call'
  rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
  railties (4.1.8) lib/rails/engine.rb:514:in `call'
  railties (4.1.8) lib/rails/application.rb:144:in `call'
  rack (1.5.2) lib/rack/lock.rb:17:in `call'
  rack (1.5.2) lib/rack/content_length.rb:14:in `call'
  rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
  C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
  C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
  C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'


  Rendered C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.1.8/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (1.0ms)
  Rendered C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.1.8/lib/action_dispatch/middleware/templates/routes/_route.html.erb (3.0ms)
  Rendered C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.1.8/lib/action_dispatch/middleware/templates/routes/_table.html.erb (1.0ms)
  Rendered C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.1.8/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb within rescues/layout (56.0ms)


Started GET "/users/sign_out" for 127.0.0.1 at 2015-11-13 11:43:11 -0500

ActionController::RoutingError (No route matches [GET] "/users/sign_out"):
  actionpack (4.1.8) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
  actionpack (4.1.8) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.1.8) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.1.8) lib/rails/rack/logger.rb:20:in `block in call'
  activesupport (4.1.8) lib/active_support/tagged_logging.rb:68:in `block in tagged'
  activesupport (4.1.8) lib/active_support/tagged_logging.rb:26:in `tagged'
  activesupport (4.1.8) lib/active_support/tagged_logging.rb:68:in `tagged'
  railties (4.1.8) lib/rails/rack/logger.rb:20:in `call'
  actionpack (4.1.8) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
  rack (1.5.2) lib/rack/runtime.rb:17:in `call'
  activesupport (4.1.8) lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call'
  rack (1.5.2) lib/rack/lock.rb:17:in `call'
  actionpack (4.1.8) lib/action_dispatch/middleware/static.rb:84:in `call'
  rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
  railties (4.1.8) lib/rails/engine.rb:514:in `call'
  railties (4.1.8) lib/rails/application.rb:144:in `call'
  rack (1.5.2) lib/rack/lock.rb:17:in `call'
  rack (1.5.2) lib/rack/content_length.rb:14:in `call'
  rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
  C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
  C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
  C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'

我看了下面的帖子,认为它可能有关系但是,我无法弄清楚这一点。

Rails ExecJS::ProgramError in Pages#home?

application.html.erb的副本

<!DOCTYPE html>
<html>
<head>
  <title></title>
  <%= render 'layouts/bootstrap' %>
  <%= stylesheet_link_tag    "application", media: "all", "data-turbolinks-track" => true %>
 <%= javascript_include_tag "default", "data-turbolinks-track" => true %>
  <%= csrf_meta_tags %>
  <%= render 'layouts/bootstrap' %>
</head>
<body>
    <div class="container">
<%= render "layouts/navbar" %>
</div>
<div class="container-fluid">
  <div class="container">
    <% flash.each do |name, msg| %>
      <% if msg.is_a?(String) %>
        <div class="alert alert-<%= name == "notice" ? "success" : "danger" %> alert-dismissable">
          <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
          <%= content_tag :div, msg, :id => "flash_#{name}" %>
        </div>
         </div>
         </div>
      <% end %>
    <% end %> 
<%= yield %>
<div class="container">
<div class="footer">
<%= render "layouts/footer" %>
</div>
</div>
</body>
</html>

3 个答案:

答案 0 :(得分:0)

如果您有default.js,那么您的应用可能需要先预先编译它。

如果是这样,您必须在config/initializers/assets

中进行设置
Rails.application.config.assets.precompile += %w( default.js )

答案 1 :(得分:0)

路由缺失消息的请求方法是[GET]

  

No route matches [GET] "/users/sign_out"

但是你只接受DELETE方法的路由定义:

destroy_user_session DELETE /users/sign_out(.:format)
new_user_session GET    /users/sign_in(.:format)
user_session POST   /users/sign_in(.:format)
destroy_user_session DELETE /users/sign_out(.:format)

因此,对该URL发出GET请求是无效的路由。

答案 2 :(得分:0)

此问题的解决方案是,application.html.erb文件中未正确声明<%= javascript_include_tag 'application' %>。我需要简化<%= javascript_include_tag "default", "data-turbolinks-track" => true %>。我不知道为什么我需要改变它才能使它发挥作用。