public
Description:
Homepage:
Clone URL: git://github.com/smtlaissezfaire/acts_as_tokenizable.git
100644 33 lines (23 sloc) 0.749 kb
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
ActsAsTokenizable
=================
 
Add a column named 'token' to your model, as a string:
 
class AddTokenStringColumnToUsers < ActiveRecord::Migration
  def self.up
    add_column :users, :token, :string
  end
 
  def self.down
    remove_column :users, :token
  end
end
 
Then open up your class, and add the following:
 
class User < ActiveRecord::Base
  acts_as_tokenizable
end
 
Now when a user gets created, he will have a unique 16 character token:
 
user = User.create!
user.token # => "3737edeca0f85e76"
 
By default, the token will only be updated once - on the first save. If you would like the token
to change after every save, you may specify that like so:
 
class User < ActiveRecord::Base
  acts_as_tokenizable :update_token => false
end