scambra/devise_invitable — Issue #183: invitable not using my custom mailers
Author: homanchou
Created: 2012-03-10 01:34:55+00:00
State: open

I upgraded from rails 3.1, devise 1.4.6, devise_invitable 0.6.1 to rails 3.2.2, devise 2.0.4 and devise_invitable 1.0.0

after the upgrade invitations are now sent using the default mailing template instead of my custom template in app/views/artists/mailer/invitation_instructions.html.erb

routes.rb:

devise_for :artists, :path => :accounts, :controllers => {:sessions => "artists/sessions",
:registrations => "artists/registrations",
:invitations => "artists/invitations",
:confirmations => "artists/confirmations" }

mappings:

Loading development environment (Rails 3.2.2)
ruby-1.9.3-preview1 :001 > y Devise.mappings[:artist]
--- !ruby/object:Devise::Mapping
scoped_path: artists
singular: :artist
class_name: Artist
klass: !ruby/object:Devise::Getter
name: Artist
path: accounts
path_prefix:
sign_out_via: :delete
format:
failure_app: !ruby/class 'Devise::FailureApp'
controllers:
:sessions: artists/sessions
:registrations: artists/registrations
:invitations: artists/invitations
:confirmations: artists/confirmations
:passwords: devise/passwords
path_names:
:registration: ''
:new: new
:edit: edit
:sign_in: sign_in
:sign_out: sign_out
:password: password
:sign_up: sign_up
:cancel: cancel
:confirmation: confirmation
:invitation: invitation
:accept: accept
modules:
- :database_authenticatable
- :rememberable
- :recoverable
- :registerable
- :validatable
- :confirmable
- :trackable
- :invitable
routes: &2174274780
- :session
- :password
- :registration
- :confirmation
- :invitation
used_routes:
- :session
- :password
- :registration
- :confirmation
- :invitation
used_helpers: *2174274780
strategies:
- :rememberable
- :database_authenticatable
=> nil

file locations:

app/views/artists/
|-- _follows.html.erb
|-- _form.html.erb
|-- confirmations
| `-- new.html.erb
|-- index.html.erb
|-- invitations
| |-- edit.html.erb
| `-- new.html.erb
|-- mailer
| |-- confirmation_instructions.html.erb
| |-- invitation_instructions.html.erb
| |-- reset_password_instructions.html.erb
| `-- unlock_instructions.html.erb
|-- passwords
| |-- edit.html.erb
| `-- new.html.erb
|-- registrations
| |-- _form.html.erb
| |-- edit.html.erb
| `-- new.html.erb
|-- sessions
| `-- new.html.erb
|-- shared
| `-- _links.erb
|-- show.html.erb
|-- show.rss.builder
`-- unlocks
`-- new.html.erb

invitations controller:

class Artists::InvitationsController < Devise::InvitationsController

def after_invite_path_for(resource)
#redirect_location(resource_name, resource)
#this is the route for which the inviter is redirected to, not the invitee
artist_path(current_artist)
end

#redirect user after they accept their inviation
def after_accept_path_for(resource)
#after_sign_in_path_for(resource)
#welcome_artist_path(resource)
#no need to redirect to welcome path to enter stuff if invitation edit page already contains it all
artist_path(current_artist)
end

#customize the invitation
def create
#params[resource_name] ==> {"email" => "abc@abc.com"}
# current_inviter ==> same as current_artist
# resource_class Artist

self.resource = resource_class.invite!(params[resource_name], current_inviter)

#set a specific type of nickname default so that when users accept invite, we can set nickname to blank in the edit form
#see artists/invitations/edit.html.erb to see how it is stripped out
self.resource.nickname = "invited_with_email_#{self.resource.id}"
begin
self.resource.save!
rescue => e
flash[:notice] = "#{e}"
redirect_to :back
return false
end

if resource.errors.empty?
set_flash_message :notice, :send_instructions, :email => self.resource.email
respond_with resource, :location => after_invite_path_for(resource)
else
respond_with_navigational(resource) { render_with_scope :new }
end
end

end