【发布时间】:2017-08-22 18:16:37
【问题描述】:
我正在使用 devise gem 进行身份验证,在登录或注册时,会创建一个 cookie:
cookies[:email] = {
:value => params[:store][:email],
:domain => :all,
:expires => 1.hour.from_now
}
cookie的目的是找到current_client:
def current_client
if cookies["email"].present?
Store.find_by_email(params[:email])
end
end
然后查看商店是否有活跃或不活跃的braintree订阅,
并将stores表下的is_active布尔值更改为true或false。
after_action :active_subscription
def active_subscription
if current_client.present?
customer_id = current_client.braintree_customer_id
customer = Braintree::Customer.find(customer_id )
customer_card = customer.payment_methods[0].token
payment_method = Braintree::PaymentMethod.find(customer_card)
sub = payment_method.subscriptions[0]
sub.status
if Braintree::Subscription::Status::Active
current_client.update_attributes(is_active: true)
end
end
但上面的active_subscription 方法不会更新is_active 列。关于我可能在这里做错了什么有什么想法吗?
【问题讨论】:
-
您分配的
cookies[:email]将始终是present?。这是你想要的吗? -
感谢@sawa 的回复。是的,我需要
cookies[:email]始终存在。否则应用在登录或注册时不会更新is_active列 -
你
if cookies["email"].present?的条件是什么? -
current_client方法的目的是找到正在尝试登录或注册的current_store,并更新stores表下的
is active列。
标签: ruby-on-rails ruby ruby-on-rails-4