Created
December 21, 2012 14:32
-
-
Save anonymous/4353169 to your computer and use it in GitHub Desktop.
Problem doing <%= @current_user.airline.name %> in view.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Airline < ActiveModel::Base | |
has_one :user, :foreign_key => "uid" | |
set_table_name "airline" | |
set_primary_key "alid" | |
attr_protected :alid | |
validates :name, :presence => true, :lenght => { :maximum => 64 } | |
validates :name_chg, :numericality => { :only_integer => true } | |
validates :uid, :numericality => { :only_integer => true } | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ActiveRecord::Base | |
belongs_to :airline | |
set_table_name "user" | |
set_primary_key "uid" | |
attr_protected :psw | |
before_save :encrypt_password | |
validates :person, :length => { :maximum => 64 } | |
validates :sex, :presence => true, :inclusion => { :in => %w(M F) } | |
validates :age, :presence => true, :numericality => { :only_integer => true } | |
validates :psw, :presence => true, :confirmation => true | |
validates :psw_confirmation, :presence => true | |
validates :confirm, :acceptance => {:accept => "1"} | |
validates :email, :presence => true, :uniqueness => true | |
validates :status, :inclusion => { :in => %w(registred activated blocked) } | |
validates :app_type, :inclusion => { :in => %w(email draugiem facebook) } | |
def self.authenticate(email="", password="") | |
user = User.find_by_email(email); | |
if user && user.match_password(password) | |
return user | |
else | |
return false | |
end | |
end | |
def match_password(login_password="") | |
psw == BCrypt::Engine.hash_secret(login_password, psw_salt) | |
end | |
private | |
def encrypt_password | |
if(psw.present?) | |
self.psw_salt = BCrypt::Engine.generate_salt | |
self.psw = BCrypt::Engine.hash_secret(psw, psw_salt) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment