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
我可以破解寶石代碼,但我想知道是否有更好的解決方案。