Here it is necessary to eliminate a number of problems:
Add this line to one of your configuration blocks (either in environment.rb , or in each of the files in config/environment ):
config.action_mailer.default_url_options = {:host => 'somewhere.com'}
In app/models/invitation.rb on line 3, you call attr_accessible :recipient_email , this will prevent the mass assignment of the sender. You should change it to this:
attr_accessible :recipient_email, :sender, :sender_id
Also invitations_controller.rb should look like this:
class InvitationsController < ApplicationController before_filter :require_analyst def new @invitation = Invitation.new end def create @invitation = Invitation.new(params[:invitation]) @invitation.sender = current_analyst if @invitation.save flash[:notice] = "Thank you, invitation sent." redirect_to root_url else render :action => 'new' end end end
You really cannot send an invitation if you are not logged in (because you need a sender, which in this case is current_analyst not @current_user ), so strings with different logic depend on whether or not.
In addition, the letter will be automatically sent using the invitation model, so the call to Mailer.deliver_invitation(@invitation, signup_url(@invitation.token)) not needed (and in fact it should be AnalystInvitationMailer.deliver_invitation(@invitation) )
Here you can see the full working patch: http://gist.github.com/290911
source share