Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove exception from skip_callback #496

Closed
wants to merge 1 commit into from
Closed

Remove exception from skip_callback #496

wants to merge 1 commit into from

Conversation

jeryRazakarison
Copy link
Contributor

skip_callback will raise an exception if the callback is not set by Devise.
But Devise doesn't always set the callback send_on_create_confirmation_instructions, (for example when :confirmable is not present).
In several cases, with the master branch of Devise, we then have an error 500

Completed 500 Internal Server Error in 78ms (ActiveRecord: 0.0ms)
ArgumentError (After create callback :send_on_create_confirmation_instructions has not been defined):
...
/Users/jery/.rvm/gems/ruby-2.2.2/bundler/gems/devise_token_auth-d154b0294006/app/controllers/devise_token_auth/registrations_controller.rb:39:in `create'

Adding the option :raise to false (as stated in rails documentation), it doesn't raise an exception when the callback has not been set by Devise, and fixes issue #397

@britg
Copy link

britg commented Jan 19, 2016

@jeryRazakarison I'm running into this issue. Why did you close this PR? I can't find any further discussion on the correct way to do this.

@britg
Copy link

britg commented Jan 19, 2016

I ended up creating an override as below, but it seems an unnecessary hack?

class Overrides::RegistrationsController < DeviseTokenAuth::RegistrationsController

  def create
    resource_class.set_callback("create", :after, :send_on_create_confirmation_instructions)
    super
  end

end

@jeryRazakarison
Copy link
Contributor Author

Hi @britg,
I closed this PR because it didn't pass the Travis Build, and so there was a risk it created unwanted side effects for other users.
I ended up overriding the create method following these instructions https://github.com/lynndylanhurley/devise_token_auth#custom-controller-overrides, but using
resource_class.skip_callback("create", :after, :send_on_create_confirmation_instructions, raise: false)
instead of
resource_class.skip_callback("create", :after, :send_on_create_confirmation_instructions)

I couldn't find a correction that passed the Travis CI build.

(Overriding was very efficient in my case, because I was able to make devise_token_auth works well with devise_invitable.)

@britg
Copy link

britg commented Jan 19, 2016

@jeryRazakarison Ok, thanks for the explanation. Looks like overriding is the way to go for now.

fivetwentysix added a commit to fivetwentysix/devise_token_auth that referenced this pull request Jan 23, 2016
fixes an issue where send_on_create_confirmation_instructions callback is
not defined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants