3
votes

Having an issue with devise. I have a sign up url that includes a token...something like: localhost:3000/users/sign_up/df293b00ae137b8b6436d45e622304aedc549072

When registration fails (passwords dont match or something) the app redirects to localhost:3000/users and displays the right flash messages from the model.

However I need the app to redirect back to the url with the token. So I throw redirect_to :back in the controller which takes me back but the flash messages dont show up.

How to I make the page redirect back (retain the exact url) and still show the flash messages.

Here is the code from the devise controller:

 def new
    resource = build_resource({})
    respond_with resource
  end

  # POST /resource
  def create
    build_resource

    if resource.save
      if resource.active_for_authentication?
        set_flash_message :notice, :signed_up if is_navigational_format?
        sign_up(resource_name, resource)
        respond_with resource, :location => after_sign_up_path_for(resource)
      else
        set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_navigational_format?
        expire_session_data_after_sign_in!
        respond_with resource, :location => after_inactive_sign_up_path_for(resource)
      end
    else
      clean_up_passwords resource
      respond_with resource
    end
  end

Any help would be great!

1
Have you tried using flash.keep before redirect_to :back? It sounds like the Flash isn't surviving the redirect. - Peter Mellett
Yeah, no dice :( just redirects back with no flash msgs - Clayton Correia
Is the redirection maybe itself redirected again? Along the lines of this answer. - Peter Mellett
Did you ever solve this? Having the same issue. - denishaskin

1 Answers

-1
votes

What you want is to write a custom FailureApp for devise, it's used to redirect a user to a given page if he is not authenticatable (autentication fails).

You can see more information about who to write and use a Failure app in the devise wiki:

https://github.com/plataformatec/devise/wiki/How-To:-Redirect-to-a-specific-page-when-the-user-can-not-be-authenticated