私は次のモデルを持っています:
class Merchant
acts_as_authentic
has_one :store
accepts_nested_attributes_for :store
end
class Store
belongs_to :merchant
end
Twitter認証にauthlogic_oauthgemを使用しています。登録中に、マーチャントとストアモデルを保存します。oauth認証を無効にすると、両方のモデルが保存されます。oauth認証を有効にすると、マーチャントインスタンスのみが保存されます。
authlogic_oauth gemコードをしばらく見てから、原因を見つけたと思います。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
gemコードをハックすることはできますが、もっと良い解決策があるかどうか疑問に思っています。