OSDN Git Service

fix: fetch fail
[pettanr/pettanr.git] / app / models / admin.rb
index abff349..5ec56f9 100644 (file)
@@ -2,12 +2,9 @@ class Admin < ActiveRecord::Base
   # Include default devise modules. Others available are:
   # , :encryptable, :lockable, :timeoutable and :omniauthable, :confirmable
   devise :database_authenticatable, :registerable,
-         :recoverable, :rememberable, :trackable, :validatable, :token_authenticatable
-
-  # Setup accessible (or protected) attributes for your model
-  attr_accessible :email, :password, :password_confirmation, :remember_me
+         :recoverable, :rememberable, :trackable, :validatable 
   
-  def active_for_authentication?\r
+  def active_for_authentication?
     super && (self.approve == 1)
   end
 
@@ -27,15 +24,16 @@ class Admin < ActiveRecord::Base
   end
   
   def self.start(email, passwd)
-    a = Admin.find(:first, :conditions => ['email = ?', email])
-    if a
-      a.password = passwd
-      a.password_confirmation = passwd
-    else
-      a = Admin.create! :email => email, :password => passwd, :password_confirmation => passwd
-    end
+    a = Admin.find_or_initialize_by(email: email)
+    a.password = passwd
+    a.password_confirmation = passwd
     a.approve = 1
     a.save!
   end
   
+  private
+  def admin_params
+    params.require(:admin).permit(:email, :password, :password_confirmation, :remember_me, :authentication_token)
+  end
+  
 end