1

I need only show a message when send the reset password instructions, I don't need redirect to new session, I overwritten the controllerPassword but when I put a redirect_to there is a error with this render.

The path used after sending reset password instructions

def after_sending_reset_password_instructions_path_for(resource_name)
  flash[:notice] = "We have sent an email with the instructions to reset your password"
  redirect_to new_user_password_path and return
end

this is the error: Render and/or redirect were called multiple times in this action......

How can I fix it?

Israel Barba
  • 1,434
  • 20
  • 28
  • Can you change the password reset form to be remote? This way it can make an ajax request and will not have to redirect anywhere? I am not that familiar with the internals of Devise. – engineersmnky Dec 30 '14 at 20:03
  • remove `and return`, it is not needed with a redirect_to – ChrisBarthol Dec 30 '14 at 20:18

3 Answers3

0

If you remove redirect_to new_user_password_path and return from your code entirely it will stop redirecting. However, if you do this it won't show your flash notice until the user manually refreshes the page. From here there are two fixes:

  • redirect to the current page to force a refresh and show the notice.
  • bind your flash notice to an AJAX request so that it's sent asynchronously. There are a lot of ways to do that, but this answer covers it pretty well.
Community
  • 1
  • 1
BarFooBar
  • 1,086
  • 2
  • 13
  • 32
0

The controller action which is calling after_sending_reset_password_instructions_path_for has a render or a redirect_to.

Try removing redirect_to in after_sending_reset_password_instructions_path_for, and let the calling action handle it.

roob
  • 1,116
  • 7
  • 11
0

I have to overwrite other class called: SessionsController < Devise::SessionsController I don't know if this is the best solution but worked for me.

This was I did:

class SessionsController < Devise::SessionsController
  # GET /resource/sign_in
  def new
    url = (request.env["HTTP_REFERER"]).to_s
    path = url.split("?").first

    if path == "http://#{Rails.application.secrets.domain_name}/users/password/new"
      redirect_to new_user_password_path and return
    end

    self.resource = resource_class.new(sign_in_params)
    clean_up_passwords(resource)
    yield resource if block_given?
    respond_with(resource, serialize_options(resource))
  end

end
Israel Barba
  • 1,434
  • 20
  • 28