我跟着设计教程: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 生成设计用户
步骤 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