def subscribe_on?
subscribe == "1"
end
class Subscription < ActiveRecord::Base
before_save { self.email = email.downcase }
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
validates :email, :presence=> true,
:format=> VALID_EMAIL_REGEX,
:if=> :subscribe_on?,
:uniqueness=> true
def subscribe_on?
self.subscribe
end
end
1.8.7-p374 :006 > Subscription.first.subscribe?
=> false
Subscription.first.subscribe?
=> false
class Subscription < ActiveRecord::Base
before_save { self.email = email.downcase }
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
us_s = self.subscribe
validates :email, :presence=> true,
:format=> VALID_EMAIL_REGEX,
:uniqueness=> true
end
Табл. - subscriptions
поля
id
name
subscribe