Rails - 没有路由匹配{:controller =>“engage / home”}#< ==导航到localhost时出错:3000 /搞

时间:2013-02-04 19:46:40

标签: ruby-on-rails ruby routes

首先,事实:

当我导航到localhost:3000 /搞时,我收到以下错误:

ActionController::RoutingError at /
No route matches {:controller=>"engage/home"}

Error image

这是我的routes.rb文件:

Kt::Application.routes.draw do

  #resources :authentications


  resources :paths


  mount Engage::Engine => '/engage', :as => 'engage'

  resources :comments do
    member {post :forresource}
  end


  resources :resources do
      member { post :vote }
      collection {get :search}
    end

  devise_for :users

  resources :userResourceView
  resources :learningPaths
  get "home/index"
  devise_scope :user do
    get "/login" => "devise/sessions#new"

  end
  devise_for :user, :path => '', :path_names => {:sign_up => "register" }

  match '/user_profile', :to =>'users#index'
  get 'tags/:tag', to: 'resources#index', as: :tag

  match '/auth/:provider/callback' => 'authentications#create'
  match '/auth/:provider/failure', :to => 'authentications#failure'
  #match '/auth/:provider/callback?error_reason...', :to => 'profiles#failure'

  match '/resources', to: 'resources#create', :via => :post
  match 'contact' => 'contact#new', :as => 'contact', :via => :get
  match 'contact' => 'contact#create', :as => 'contact', :via => :post
  match '/forums' => 'forums#index'

  root to: 'home#index', :as => :home

当我运行rake路线时,我得到以下内容:

155-99-191-20:KnowledgeThief dainewinters$ rake routes
                   paths GET    /paths(.:format)                     paths#index
                         POST   /paths(.:format)                     paths#create
                new_path GET    /paths/new(.:format)                 paths#new
               edit_path GET    /paths/:id/edit(.:format)            paths#edit
                    path GET    /paths/:id(.:format)                 paths#show
                         PUT    /paths/:id(.:format)                 paths#update
                         DELETE /paths/:id(.:format)                 paths#destroy
                  engage        /engage                              Engage::Engine
     forresource_comment POST   /comments/:id/forresource(.:format)  comments#forresource
                comments GET    /comments(.:format)                  comments#index
                         POST   /comments(.:format)                  comments#create
             new_comment GET    /comments/new(.:format)              comments#new
            edit_comment GET    /comments/:id/edit(.:format)         comments#edit
                 comment GET    /comments/:id(.:format)              comments#show
                         PUT    /comments/:id(.:format)              comments#update
                         DELETE /comments/:id(.:format)              comments#destroy
           vote_resource POST   /resources/:id/vote(.:format)        resources#vote
        search_resources GET    /resources/search(.:format)          resources#search
               resources GET    /resources(.:format)                 resources#index
                         POST   /resources(.:format)                 resources#create
            new_resource GET    /resources/new(.:format)             resources#new
           edit_resource GET    /resources/:id/edit(.:format)        resources#edit
                resource GET    /resources/:id(.:format)             resources#show
                         PUT    /resources/:id(.:format)             resources#update
                         DELETE /resources/:id(.:format)             resources#destroy
        new_user_session GET    /users/sign_in(.:format)             devise/sessions#new
            user_session POST   /users/sign_in(.:format)             devise/sessions#create
    destroy_user_session DELETE /users/sign_out(.:format)            devise/sessions#destroy
           user_password POST   /users/password(.:format)            devise/passwords#create
       new_user_password GET    /users/password/new(.:format)        devise/passwords#new
      edit_user_password GET    /users/password/edit(.:format)       devise/passwords#edit
                         PUT    /users/password(.:format)            devise/passwords#update
cancel_user_registration GET    /users/cancel(.:format)              devise/registrations#cancel
       user_registration POST   /users(.:format)                     devise/registrations#create
   new_user_registration GET    /users/sign_up(.:format)             devise/registrations#new
  edit_user_registration GET    /users/edit(.:format)                devise/registrations#edit
                         PUT    /users(.:format)                     devise/registrations#update
                         DELETE /users(.:format)                     devise/registrations#destroy
  userResourceView_index GET    /userResourceView(.:format)          userResourceView#index
                         POST   /userResourceView(.:format)          userResourceView#create
    new_userResourceView GET    /userResourceView/new(.:format)      userResourceView#new
   edit_userResourceView GET    /userResourceView/:id/edit(.:format) userResourceView#edit
        userResourceView GET    /userResourceView/:id(.:format)      userResourceView#show
                         PUT    /userResourceView/:id(.:format)      userResourceView#update
                         DELETE /userResourceView/:id(.:format)      userResourceView#destroy
           learningPaths GET    /learningPaths(.:format)             learningPaths#index
                         POST   /learningPaths(.:format)             learningPaths#create
        new_learningPath GET    /learningPaths/new(.:format)         learningPaths#new
       edit_learningPath GET    /learningPaths/:id/edit(.:format)    learningPaths#edit
            learningPath GET    /learningPaths/:id(.:format)         learningPaths#show
                         PUT    /learningPaths/:id(.:format)         learningPaths#update
                         DELETE /learningPaths/:id(.:format)         learningPaths#destroy
              home_index GET    /home/index(.:format)                home#index
                   login GET    /login(.:format)                     devise/sessions#new
        new_user_session GET    /sign_in(.:format)                   devise/sessions#new
                         POST   /sign_in(.:format)                   devise/sessions#create
    destroy_user_session DELETE /sign_out(.:format)                  devise/sessions#destroy
                         POST   /password(.:format)                  devise/passwords#create
                         GET    /password/new(.:format)              devise/passwords#new
                         GET    /password/edit(.:format)             devise/passwords#edit
                         PUT    /password(.:format)                  devise/passwords#update
                         GET    /cancel(.:format)                    devise/registrations#cancel
                         POST   /                                    devise/registrations#create
                         GET    /register(.:format)                  devise/registrations#new
                         GET    /edit(.:format)                      devise/registrations#edit
                         PUT    /                                    devise/registrations#update
                         DELETE /                                    devise/registrations#destroy
            user_profile        /user_profile(.:format)              users#index
                     tag GET    /tags/:tag(.:format)                 resources#index
                                /auth/:provider/callback(.:format)   authentications#create
                                /auth/:provider/failure(.:format)    authentications#failure
                         POST   /resources(.:format)                 resources#create
                 contact GET    /contact(.:format)                   contact#new
                 contact POST   /contact(.:format)                   contact#create
                  forums        /forums(.:format)                    forums#index
                    home        /                                    home#index

Routes for Engage::Engine:
                       root        /                                                 engage/topics#index
             topic_comments POST   /topics/:topic_id/comments(.:format)              engage/comments#create
          new_topic_comment GET    /topics/:topic_id/comments/new(.:format)          engage/comments#new
              topic_comment DELETE /topics/:topic_id/comments/:id(.:format)          engage/comments#destroy
                 topic_vote GET    /topics/:topic_id/vote(.:format)                  engage/votes#create
                            POST   /topics/:topic_id/vote(.:format)                  engage/votes#create
                            DELETE /topics/:topic_id/vote(.:format)                  engage/votes#destroy
unsubscribe_topic_following GET    /topics/:topic_id/following/unsubscribe(.:format) engage/followings#destroy
            topic_following GET    /topics/:topic_id/following(.:format)             engage/followings#create
                            POST   /topics/:topic_id/following(.:format)             engage/followings#create
                            DELETE /topics/:topic_id/following(.:format)             engage/followings#destroy
                     topics GET    /topics(.:format)                                 engage/topics#index
                            POST   /topics(.:format)                                 engage/topics#create
                  new_topic GET    /topics/new(.:format)                             engage/topics#new
                 edit_topic GET    /topics/:id/edit(.:format)                        engage/topics#edit
                      topic GET    /topics/:id(.:format)                             engage/topics#show
                            PUT    /topics/:id(.:format)                             engage/topics#update
                            DELETE /topics/:id(.:format)                             engage/topics#destroy
        set_intended_action POST   /set_intended_action(.:format)                    engage/application#set_intended_action
          user_user_profile PUT    /users/:user_id/user_profile(.:format)            engage/user_profiles#update
                      users GET    /users(.:format)                                  engage/users#index

此外,该错误提到了app / views / shared / _header.html.erb。这是该文件:

<div id="header">

    <div id="logoText">

        <%= link_to "Knowledge Thief", url_for(:action=>"index", :controller=>"home") %> 
    </div>

    <div class="signin">

    <a href="#">

        <div class="notifications unread">

            3

        </div>

    </a>

       <% unless current_user.nil? %>
           <%= link_to "#{current_user.email}", url_for(:action=>"user") %>
       <% else %>
           <%= link_to "Sign In", url_for(current_user) %>
       <% end %>
        <%= link_to image_tag("downArrow.png", :style => "height:5px;margin-left:3px;vertical-align:middle;"), url_for(current_user) %> 
    </div>


 </div>

到目前为止我已采取的步骤(将会更新):

  1. 确保捆绑安装
  2. Ran rake db:reset
  3. Ran rake db:migrate
  4. 问我的团队两天前和现在之间可能发生了什么。我将通过git log等查看。
  5. 现在,我可以看到/参与被引导到参与,但这个/家在哪里?不应该/只是去参与/主题#index?

1 个答案:

答案 0 :(得分:2)

您的主应用程序中是否设置了家庭控制器?原因在于 _header.html.erb 文件,您使用链接来指定家庭控制器的操作。

我猜你正在使用主应用程序的布局/模板来渲染引擎的视图。 _header.html.erb 也是呈现引擎视图的模板的一部分。

可挂载引擎在轨道中的工作方式是,如果要访问主应用程序控制器/操作的路径,则需要在 main_app 上调用。因此,您可以将 link_to 行更改为:

<%= link_to "Knowledge Thief", main_app.home_path %>