There's a number of problems you need to fix:
Add this line to one of your config blocks (either in environment.rb
or 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 have call attr_accessible :recipient_email
this will prevent you from mass assigning 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 can't send an invitation unless you're logged in (because you need a sender, which in this case is an current_analyst
not @current_user
), so the lines having different logic depending on being logged in or not has been removed.
Also, the email will be automatically sent by the Invitation model so calling Mailer.deliver_invitation(@invitation, signup_url(@invitation.token))
is unnecessary (and actually it would have to be AnalystInvitationMailer.deliver_invitation(@invitation)
)
You can see a full working patch here: http://gist.github.com/290911