/
devise installation
123 lines (85 loc) · 3.58 KB
/
devise installation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
gem install devise
rails generate devise:install
rails generate devise User
In your routes file
==================================================================================================
root :to => "home#index"
In your development environment file
==================================================================================================
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
In your user model, I have added first_name attr_accessible
==================================================================================================
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :first_name, :email, :password, :password_confirmation, :remember_me
end
Default route setup
==================================================================================================
devise_for :users do
get "sign_in", :to => "devise/sessions#new"
end
now point to your browser
http://localhost:3000/sign_in
In migration file add column
====================================================================================================
class DeviseCreateUsers < ActiveRecord::Migration
def self.up
create_table(:users) do |t|
t.database_authenticatable :null => false
t.recoverable
t.rememberable
t.trackable
t.column :first_name, :string
# t.encryptable
# t.confirmable
# t.lockable :lock_strategy => :failed_attempts, :unlock_strategy => :both
# t.token_authenticatable
t.timestamps
end
add_index :users, :email, :unique => true
add_index :users, :reset_password_token, :unique => true
# add_index :users, :confirmation_token, :unique => true
# add_index :users, :unlock_token, :unique => true
# add_index :users, :authentication_token, :unique => true
end
def self.down
drop_table :users
end
end
**rails generate devise:views users
It will copy view file to your view folder.
inside “config/initializers/devise.rb”
** config.scoped_views = true”
**device controller specific core written like
http://stackoverflow.com/questions/3546289/override-devise-registrations-controller
after write your code in controller, you have to modify your application.rb file
config/application.rb
paths.app.views << "app/views/devise"
Default route setup
==================================================================================================
devise_for :users do
get "sign_in", :to => "devise/sessions#new"
end
now point to your browser
http://localhost:3000/sign_in
=====================================================================================================
:path => allows you to setup path name that will be used, as rails routes does.
the following route configuration would setup your route as /accounts instead of /users:
devise_for :users, :path => "account"
*** routes
rake routes
**
http://localhost:3000/users/sign_in
http://localhost:3000/users/password/new
http://localhost:3000/users/sign_in
# how to recover undefined method `database_authenticatable' for #<ActiveRecord::ConnectionAdapters::TableDefinition:0x9faa9fc>
A. update your devise gem.
gem devise, '2.1.1'
bundle install
rails generate devise install
rake db:migrate
ra