Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with accepts_nested_attributes_for and authlogic_oauth #8

Open
kandadaboggu opened this issue Jan 28, 2010 · 2 comments
Open

Comments

@kandadaboggu
Copy link

I have the following models:
class Merchant
acts_as_authentic
has_one :store
accepts_nested_attributes_for :store
end
class Store
belongs_to :merchant
end
I am using authlogic_oauth gem for Twitter authentication. While registration I save the Merchant and the Store model. If I disable the oauth authentication both models are saved. When ever I enable the oauth authentication only Merchant instance is saved.

After spending some time looking at the authlogic_oauth gem code I think found the culprit. The authlogic_oauth gem stores the ActiveRecord attributes in the session during oauth calls. But it does not store the attributes of the associations.

# 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

I addressed the issue by saving Store attributes temporarily in the session for the duration of Oauth calls.

class MerchantsController < ApplicationController
    before_filter :init_nested_attr
    def create
        @merchant = Merchant.new(params[:merchant])
        @merhcant.save do |result|
            #some code
        end
    end
    private
    def init_nested_attr
        if session[:authlogic_oauth_attributes]
            params[:merchant] = session[:authlogic_oauth_attributes]
            params[:merchant][:store_attributes] = session.delete(:authlogic_oauth_store_attributes)
        else
            session[:authlogic_oauth_store_attributes] = params[:merchant][:store_attributes]
        end
    end
end

I am wondering if there is a better solution.

@travisjtodd
Copy link

Thanks for this solution. I am having the same issue. Would also like to know if there is a better option.

@kandadaboggu
Copy link
Author

I couldn't find anything better. Off-course the OAuth gem could be modified to store the the associations. I didn't go down that route.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants