devise_invitable
devise_invitable copied to clipboard
undefined method `accept_invitation_url'
The route created is named accept_resource_invitation
, but the bundled views call accept_invitation_url
.
I will customize my views anyways, but in the README it says
All the views are packaged inside the gem. If you'd like to customize the views, invoke the following generator and it will copy all the views to your application
Did I do something wrong in the setup or is the README not clear here?
Using Devise 4.2 with ActiveAdmin 1.0pre4 and Rails 5.
Devise creates accept_invitation_url helper, with resource as first parameter, and use this resource to call accept_resource_invitation_url
Usual setup doesn't include copying views to your application, if you need to change something in views, you can run rails generate devise_invitable:views as README explains
I have the same issue on devise_invitable 1.7.0:
$ cat Gemfile.lock | grep devise
devise (4.2.0)
devise_invitable (1.7.0)
devise (>= 4.0.0)
devise
devise_invitable (~> 1.7.0)
Upon calling User.invite!(email: "[email protected]")
I got:
Rendering devise/mailer/invitation_instructions.html.erb
Rendered devise/mailer/invitation_instructions.html.erb (205.5ms)
Devise::Mailer#invitation_instructions: processed outbound mail in 260.2ms
ActionView::Template::Error: undefined method `accept_invitation_url' for #<#<Class:0x007f95ed2852f0>:0x007f95ed2756e8>
from /Users/tmacdonald/src/censored/app/views/devise/mailer/invitation_instructions.html.erb:5:in `_app_views_devise_mailer_invitation_instructions_html_erb__2361615884932153388_70140952850380'
from /Users/tmacdonald/.rvm/gems/ruby-2.2.3@censored/gems/actionview-5.0.0.1/lib/action_view/template.rb:158:in `block in render'
I then ran rails g devise_invitable:views
, went into app/views/devise/mailer/invitation_instructions.{html,text}.erb
, and changed accept_invitation_url
to accept_user_invitation_url
on Line 5 of both files.
Are there any situations where it shouldn't be accept_user_invitation_url
to begin with? Would you welcome a PR making this 10-character change?
accept_user_invitation_url will work only if your model is user
As you can see, accept_invitation_url has @resource as first parameter, and accept_user_invitation_url shouldn't have it, it should be accept_user_invitation_url(:invitation_token => @token)
Devise uses similar url methods: https://github.com/plataformatec/devise/blob/master/app/views/devise/mailer/confirmation_instructions.html.erb#L5
I saw this too and I thought it was because I had subclassed the Devise::Mailer without including Devise::Controllers::UrlHelpers as described here: https://github.com/plataformatec/devise/wiki/How-To:-Use-custom-mailer
Commenting the config.mailer
line in my devise config "fixed" it but then subsequent startups of the app with the mailer uncommented worked as well.
I now can't seem to reproduce it at all. I wonder if perhaps there's a race condition or an ordering condition on loading the Devise::Controllers::UrlHelpers in time for this method to be present.