我有以下型号:
class Merchant
acts_as_authentic
has_one :store
accepts_nested_attributes_for :store
end
class Store
belongs_to :merchant
end
我正在使用AuthLogic_oauth gem进行Twitter身份验证。注册时,我会保存商家和商店模型。如果禁用OAuth身份验证,两个模型都将被保存。当我启用OAuth身份验证时,只保存商家实例。
在花了一段时间看了AuthLogic_oauth gem代码之后,我认为找到了罪魁祸首。AuthLogic_OAuth gem在OAuth调用期间将ActiveRecord属性存储在会话中。但它不存储关联的属性。
def save(perform_validation = true, &block)
if perform_validation && block_given? && redirecting_to_oauth_server?
session_class.controller.session[:authlogic_oauth_attributes] = attributes.reject!{|k, v| v.blank?}
end
end
我可以破解gem代码,但我想知道是否有更好的解决方案。