0

I have devise set up with custom controller (user controller), just like explained here.

I customised some of the controller logic like so

def create

  super do |user|
    @patient = user.build_patient
    @patient.save
  end

end

All of that works fine. The problem is when I try to provide custom redirect_to, then I see

def create

  super do |user|
    @patient = user.build_patient
    @patient.save
  end

  redirect_to physicians_path
end

Solutions to the general problem of having (accidental or otherwise) > 1 redirect_to inside a controller won't work because i) I can't affect the first one (since its part of devise), and ii) I don't know how to tell it to ignore the first one and use the one I specify instead

stevec
  • 41,291
  • 27
  • 223
  • 311

1 Answers1

0

I won't accept this answer, because I'm sure there's a better way, but here's what worked anyway:

  1. Copy the code from the relevant controller in the devise code
  2. Edit it however you want
  3. I didn't use super (I think it would be better to, but I didn't figure out how)

So I simply added this

def update

  self.resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key)
  prev_unconfirmed_email = resource.unconfirmed_email if resource.respond_to?(:unconfirmed_email)

  resource_updated = update_resource(resource, account_update_params)
  yield resource if block_given?
  if resource_updated
    set_flash_message_for_update(resource, prev_unconfirmed_email)
    bypass_sign_in resource, scope: resource_name if sign_in_after_change_password?

    # respond_with resource, location: after_update_path_for(resource)
    redirect_to edit_user_registration_path
  else
    clean_up_passwords resource
    set_minimum_password_length
    respond_with resource
  end

end

Note the only difference from the devise code is commenting out this

    # respond_with resource, location: after_update_path_for(resource)

and adding this in its place

    redirect_to edit_user_registration_path
stevec
  • 41,291
  • 27
  • 223
  • 311