2015-05-06 88 views
2

我有一個沒有問題的網站。這裏是路線文件:如何啓用註冊

Testpager::Application.routes.draw do 
    devise_for :users 
    resources :news,  only: [:index, :show] 
    resources :documents, only: [:index, :show] 

    namespace :admin do 
    resources :documents, only: [:index, :show, :destroy, :edit, :update, :new, :create] 
    resources :news,  only: [:index, :show, :destroy, :edit, :update, :new, :create] 
    get "admin" => 'documents#index' 
    end 

    get "contacts/index" 
    get "services/index" 
    get "index/index" 
    get "admin/index" 

    root 'index#index' 
end 

我想添加一個註冊系統。爲此,我使用Devise

我的行動是:

  1. 我裝的設計寶石。
  2. rails g devise:install
  3. 將此添加到application.html.erb:

    <p class="notice"><%= notice %></p> 
    <p class="alert"><%= alert %></p> 
    
  4. rails g devisw User

  5. rake db:migrate
  6. rails server
  7. 我打開URL http://localhost:3000/users/sign_up

我得到了以下錯誤消息:

ActionController::UrlGenerationError in Devise::Registrations#new 
Showing /home/kalinin/rails/testpager/app/views/shared/_nav_main.html.erb where line #6 raised: 
No route matches {:action=>"index", :controller=>"devise/index"} 
Extracted source (around line #6):  
    <ul> 
     <li> 
      <%= link_to 'index', controller: "index", action: "index" %> 
     </li> 
Trace of template inclusion: app/views/layouts/application.html.erb 

這裏是控制器:

class IndexController < ApplicationController 
    def index 
    end 
end 

爲索引控制器的視圖存在。

+4

不要命名你的控制器'IndexController',它只會導致混淆。在它所代表的資源之後命名它。 –

回答