1

首先,事实:

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

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

错误图片

这是我的 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. 运行 rake db:reset
  3. 运行 rake db:migrate
  4. 问我的团队两天前到现在之间可能发生了什么。我将查看 git log 等。

现在,我可以看到 /engage 被路由到了 engage,但是这个 /home 是从哪里来的呢?/engage 不应该只是去参与/topics#index 吗?

4

1 回答 1

2

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

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

rails 中的可挂载引擎的工作方式是,如果您想访问主应用程序的控制器/动作的路由,您需要调用main_app。因此,您可以将link_to行更改为如下所示:

<%= link_to "Knowledge Thief", main_app.home_path %> 
于 2013-02-04T20:18:11.307 回答