OSDN Git Service

iroiro
[pettanr/pettanr.git] / app / models / author.rb
1 class Author < ActiveRecord::Base
2   has_one :artist
3   
4   # Include default devise modules. Others available are:
5   # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
6   devise :database_authenticatable, :registerable,
7          :recoverable, :rememberable, :trackable, :token_authenticatable, :validatable#, :confirmable
8
9   # Setup accessible (or protected) attributes for your model
10   attr_accessible :id, :name, :password, :password_confirmation, :remember_me #, :email
11
12   before_save do |r|
13     r.name = 'no name' if r.name.blank?
14   end
15   
16   def artist?
17     Artist.find_by_author(self) != nil
18   end
19   
20   def create_token
21     self.ensure_authentication_token
22     self.save
23   end
24   
25   def delete_token
26     self.authentication_token = nil
27     self.save
28   end
29   
30   def step2 n
31     self.name = n
32     self.save
33   end
34   
35 end