title: Rails: Rendering different views for a devise login depending on the stored location
body: <p>I am using a bookmarklet that loads an iframe. I am using devise for authentication. If the iframe loads and tries to hit the 'bookmark' action but needs to authenticate, it obviously redirects the iframe to the sign_in path before forwarding onto the '<code>bookmark</code>' action. I want the '<code>sessions/new</code>' action (the login page) to render with a different layout at this point so that the login page fits inside the iframe. Devise uses a <code>render_with_scopes</code> method though rather than a standard render method and passing it a <code>:layout =&gt; 'my_iframe_layout'</code> option does not work. I tried taking the <code>render_with_scope</code> method out of the <code>lib</code> module file and placing it in my controller but it created errors in the stack that caused a server crash.</p>
  
  <p>I think I need a sessions controller method that looks something like this:</p>
  
  <pre><code>    def new
      resource = build_resource
      clean_up_passwords(resource)
      #test whether the destination of this request is the bookmark action (mapped to /add_site)
      if after_sign_in_path_for(resource)[0..8] == '/add_site'
        respond_with_navigational(resource, stub_options(resource)){ render_with_scope :new }
    :layout =&gt; "bookmark_layout"    
      else
        respond_with_navigational(resource, stub_options(resource)){ render_with_scope :new }
      end
  end
  </code></pre>
  
  <p>The only hack I thought of was to have a special authenticate method for my '<code>bookmark</code>' action that tests what the destination action is and then authenticates accordingly but that doesn't seem very DRY.</p>