Store redirect url for later use in rails 4
<p>I am working on rails 4 application and I am consuming / using API of another site say example.com, which uses 3-legged oauth authorization (same as twitter). To achieve this functionality I have used this <a href="https://stackoverflow.com/questions/16516398/twitter-3-legged-authorization-in-ruby/16519829#16519829">link</a> and implemented the same. </p>

<p>Here is my implementation</p>

<p><strong>AuthController</strong></p>

<pre><code>class AuthController &lt; ApplicationController
  before_filter :authenticate_user!
  before_filter :fetch_request_token, only: [:authorize]

  def authorize
    token = @consumer.get_request_token(oauth_callback: 'http://localhost:3000/auth/fetch_access_token')
    authorize_url = token.authorize_url
    redirect_to authorize_url
  end

  def fetch_access_token
    acc_token = request_token.get_access_token(oauth_verifier: params[:oauth_verifier])
    # remaining logic
    redirect_to files_jds_path
  end

  private

  def fetch_request_token
    #logic for fetching request token
  end
end
</code></pre>

<p><strong>JDsController</strong></p>

<pre><code>class JDsController &lt; AuthController
  before_filter :authorize, only: [:files, :field_info] unless: :check_access_token

  def files
    # logic for the files
  end

  def field_info
    # logic for the files
  end

  private

  def check_access_token
    # logic for checking access_token
  end
end
</code></pre>

<p>Currently I am checking the access_token present or not before any action, if access_token not present, then I am fetching the access_token using authorize method.</p>

<p>If you see the <code>fetch_access_token</code> method from the <code>AuthController</code> (this is my callback url), where I have hard-coded redirect path as <code>files_jds_path</code>. </p>

<p>Because of this implementation though before_filter applied to the <code>field_info</code>, after fetching access_token it redirect to the <code>files_jds_path</code>.</p>

<p>But I need to make it generalized so that for any action it will redirect to the respective path.</p>

<p>Can anyone suggest how can I do this</p>