1

私はdeviseのチュートリアルを続けました: http://railscasts.com/episodes/209-introducing-devise

localhost:3000/users/registration/sign_up でエラーページが表示されるため、この質問をします。

Showing /home/alon/.rvm/gems/ruby-1.9.3-p327/gems/devise-1.1.rc0/app/views/devise/registrations/new.html.erb where line #3 raised:

undefined method `user_registration_path' for #<#<Class:0xb6388a90>:0xb63874b0>
Extracted source (around line #3):

1: <h2>Sign up</h2>
2: 
3: <%= form_for(resource_name, resource, :url => registration_path(resource_name)) do |f| %>
4:   <%= f.error_messages %>
5:   <p><%= f.label :email %></p>
6:   <p><%= f.text_field :email %></p>
Rails.root: /home/alon/projects/TODOLIST

チュートリアルでは、localhost:3000/users/sign_up と入力する必要がありますが、エラーが発生しました:

Routing Error

No route matches [GET] "/users/sign_up"
Try running rake routes for more information on available routes.

彼のプロジェクトをプルできませんか: github.com/plataformatec/devise ? もしそうなら、必要なものはすべて揃っていますよね?git clone git@github.com:josevalim/devise.git でやってます。

答えがノーなら、

これらは私が行った手順です:

ステップ 1) Rails new TODOLIST

ステップ 2)レール -v

Rails 3.2.9

ステップ 3) sudo gem install devise --version=1.1.rc0

[sudo] password for alon: 
sudo: gem: command not found

ステップ 4)を編集しGemfileます。

source 'https://rubygems.org'

gem 'rails', '3.2.9'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'sqlite3'
gem 'devise', '1.1.rc0'

# Gems used only for assets and not required
# in production environments by default.
group :assets do
    gem 'sass-rails',   '~> 3.2.3'
    gem 'coffee-rails', '~> 3.2.1'

    # See https://github.com/sstephenson/execjs#readme for more supported runtimes
    # gem 'therubyracer', :platforms => :ruby

    gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'

ステップ 5)バンドルのインストール

ステップ 6) Rails は devise_install を生成します

ステップ 7) routes.rb を編集します。

TODOLIST::Application.routes.draw do
    devise_for :users
    root :to => "home#index"
end

ステップ 8) development.rb を編集します。

TODOLIST::Application.configure do
    # Settings specified here will take precedence over those in config/application.rb

    # In the development environment your application's code is reloaded on
    # every request. This slows down response time but is perfect for development
    # since you don't have to restart the web server when you make code changes.
    config.cache_classes = false

    # Log error messages when you accidentally call methods on nil.
    config.whiny_nils = true

    # Show full error reports and disable caching
    config.consider_all_requests_local       = true
    config.action_controller.perform_caching = false

    # Don't care if the mailer can't send
    config.action_mailer.raise_delivery_errors = false

    # Print deprecation notices to the Rails logger
    config.active_support.deprecation = :log

    # Only use best-standards-support built into browsers
    config.action_dispatch.best_standards_support = :builtin

    # Raise exception on mass assignment protection for Active Record models
    config.active_record.mass_assignment_sanitizer = :strict

    # Log the query plan for queries taking more than this (works
    # with SQLite, MySQL, and PostgreSQL)
    config.active_record.auto_explain_threshold_in_seconds = 0.5

    # Do not compress assets
    config.assets.compress = false

    # Expands the lines which load the assets
    config.assets.debug = true

    config.action_mailer.default_url_options = { :host => 'localhost:3000' }
end

ステップ 9) rails generate device ユーザー

ステップ 10) user.rb を編集します。

class User < ActiveRecord::Base
    # Include default devise modules. Others available are:
    # :token_authenticatable, :lockable, :timeoutable, :confirmable and :activatable
    devise :database_authenticatable, :registerable,
           :recoverable, :rememberable, :trackable, :validatable

    # Setup accessible (or protected) attributes for your model
    attr_accessible :email, :password, :password_confirmation
    # attr_accessible :title, :body
end

**ステップ 11) 20121225122457_devise_create_users.rb を編集:

class DeviseCreateUsers < ActiveRecord::Migration
    def self.up
      create_table(:users) do |t|
         t.database_authenticatable :null => false
         # t.confirmable
         t.recoverable
         t.rememberable
         t.trackable
         # t.lockable :lock_strategy => :failed_attempts, :unlock_strategy => :both

         t.timestamps
       end

       add_index :users, :email,                :unique => true
       #add_index :users, :confirmation_token,   :unique => true
       add_index :users, :reset_password_token, :unique => true
       # add_index :users, :unlock_token,         :unique => true
  end

  def self.down
      drop_table :users
  end
end

ステップ 12) rake db:migrate

ステップ 13)レーキ ルート

new_user_session GET    /users/sign_in(.:format)              devise/sessions#new
user_session POST   /users/sign_in(.:format)              devise/sessions#create
destroy_user_session GET    /users/sign_out(.:format)             devise/sessions#destroy
password POST   /users/password(.:format)             devise/passwords#create {:name_prefix=>:user}
new_password GET    /users/password/new(.:format)         devise/passwords#new {:name_prefix=>:user}
edit_password GET    /users/password/edit(.:format)        devise/passwords#edit {:name_prefix=>:user}
        PUT    /users/password(.:format)             devise/passwords#update {:name_prefix=>:user}
        POST   /users/registration(.:format)         devise/registrations#create {:name_prefix=>"user_registration"}
new GET    /users/registration/sign_up(.:format) devise/registrations#new {:name_prefix=>"user_registration"}
edit GET    /users/registration/edit(.:format)    devise/registrations#edit {:name_prefix=>"user_registration"}
        PUT    /users/registration(.:format)         devise/registrations#update {:name_prefix=>"user_registration"}
        DELETE /users/registration(.:format)         devise/registrations#destroy {:name_prefix=>"user_registration"}
   root        /                                     home#index
4

1 に答える 1

1

これは、デバイスのバージョンに関連しています。

レール3.2でデバイス1を使用しないでください...デバイスのバージョンを2にアップグレードしてください>

于 2012-12-25T14:47:01.347 に答える