1
votes

I followed by the tutorial for devise: http://railscasts.com/episodes/209-introducing-devise

I ask this question because localhost:3000/users/registration/sign_up let me an error page:

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

in the tutorial, I have to enter: localhost:3000/users/sign_up, but I got errors:

Routing Error

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

can't I pull his project: github.com/plataformatec/devise ? if so, I will have all I need, right? I do it by: git clone [email protected]:josevalim/devise.git

if the answer is no,

These are the steps I did:

step 1) rails new TODOLIST

step 2) rails -v

Rails 3.2.9

step 3) sudo gem install devise --version=1.1.rc0

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

step 4) edit the 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'

step 5) bundle install

step 6) rails generate devise_install

step 7) edit the routes.rb:

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

step 8) edit the 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

step 9) rails generate devise User

step 10) edit 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

**step 11) edit 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

step 12) rake db:migrate

step 13) rake routes

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
1

1 Answers

1
votes

This is related to your devise version.

Don't use devise 1 with rails 3.2... Upgrade your devise version to 2 >