Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7195779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:38:52+00:00 2026-05-28T20:38:52+00:00

I have a situation where an action is called on a CallbackController. I have

  • 0

I have a situation where an action is called on a CallbackController. I have no control over this as it is prescribed by a framework. In response to this action I need to create a new Authentication. My AuthenticationController has create and a destroy actions.

How should I proceed? It seems to me my options are:

  1. Duplicate the code from AuthenticationCOntroller’s create action into my CallbackController (Obviously far from DRY)
  2. Call the create method directly from the CallbackController (This kind of inter-controller-communication seems to be frowned on)
  3. Break the code from the AuthenticationController’s create action out into a helper class which is shared between the two controllers

None of these seem like the correct answer. So can anyone suggest a better approach?

My callbacks controller:

class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController

  def facebook
    authorize
  end


  def twitter
    authorize
  end

  private

    def authorize
      omniauth_data = request.env["omniauth.auth"]
      #Check to see if we have an authentication for this provider already
      authentication = Authentication.find_by_provider_and_uid(omniauth_data['provider'], omniauth_data['uid'])
      #If an authentication already exists, sign its User in
      #Otherwise create a new authentication for the current user
      if authentication
        flash[:notice] = "Signed in successfully with " +  omniauth_data['provider']
        sign_in_and_redirect(:user, authentication.user)
      elsif current_user
        current_user.authentications.create(:provider => omniauth_data['provider'], :uid => omniauth_data['uid'])
        flash[:notice] = "Authentication successful"
        redirect_to user_profile_url
      else
        user = User.new
        user.apply_omniauth_data_as_authentication(omniauth_data)
        if user.save
          flash[:notice] = "Signed in successfully with " +  omniauth_data['provider']
          sign_in_and_redirect(:user, authentication.user)
        else
          #save the omniauth data in a session so we can add the authentication once registration is complete
          session[:omniauth] = omniauth_data.except('extra')
          redirect_to new_user_registration_url
        end
      end
    end

end

and my authentications controller:

class AuthenticationsController < ApplicationController

  #Controller for representing Authentications provided by

  def index
    current_user.authentications if current_user
  end

  def create

  end

  def destroy
    @authentication = Authentication.find(params[:id])
    provider = @authentication.provider
    @authentication.destroy
    flash[:notice] = "Destroyed authentication from "+provider
    redirect_to authentications_url
  end

end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T20:38:53+00:00Added an answer on May 28, 2026 at 8:38 pm

    If you control the code for both CallbackController and AuthenticationController (they’re not coming from the framework), you could pull the common code out into a common superclass. Or just put it in a module and include it.

    Rather than cut-and-pasting the entire create and destroy methods into a new Module, I would be inclined to find smaller, coherent parts and put them in methods with meaningful names. It may be that the create and destroy methods on both CallbackController and AuthenticationController can be implemented in just 2 or 3 lines using those smaller methods.

    If you pull coherent groups of lines out into smaller methods, you could consider adding those methods as an extension to ActionController::Base if it seems appropriate. (i.e. if they are general enough.) If the small methods are useful in other parts of the application, that’s a bonus.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have situation like this: user submits form with action='/pay' in '/pay' I have
I have situation where I need to change the order of the columns/adding new
Here is my situation: I have a controller action called OrderFromCategory which fills a
i have situation like this: class IData { virtual void get() = 0; virtual
Here is the situation: I have been called upon to work with InstallAnywhere 8,
The situation: Say I have an example controller called AccountController with some actions of
Hellow stackoverflow people, I am pretty new to Cocoa. I have XCode 3.1 Situation:
I have a situation where i want to replicate the action of the keys
I have a situation in which I need to set a date and time
Here's the premise: I have many classes where I need to perform an action

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.