0
我有以下型号:问题与accepts_nested_attributes_for同时使用authlogic_oauth
class Merchant
acts_as_authentic
has_one :store
accepts_nested_attributes_for :store
end
class Store
belongs_to :merchant
end
我使用authlogic_oauth宝石Twitter的认证。在注册时,我保存商家和商店模型。如果我禁用oauth认证,则保存这两个模型。当我启用oauth身份验证时,只保存商户实例。
花了一些时间看看authlogic_oauth宝石代码后,我认为找到了罪魁祸首。 authlogic_oauth gem在oauth调用期间将ActiveRecord属性存储在会话中。但它不存储关联的属性。
# authlogic_oauth : lib/authlogic_oauth/acts_as_authentic.rb
def save(perform_validation = true, &block)
if perform_validation && block_given? && redirecting_to_oauth_server?
# My comment: Any nested attributes are not saved in the session
session_class.controller.session[:authlogic_oauth_attributes] = attributes.reject!{|k, v| v.blank?}
# some code
end
# some code
end
我可以破解宝石代码,但我想知道是否有更好的解决方案。