views:

251

answers:

1

Hi,

I have been trying to create beta invites that each existing user can send out and was hoping to be able to use a plugin called acts_as_inviteable http://github.com/brianjlandau/acts_as_inviteable

I was wondering if anyone had direct experience with it. When I checked the console, it appears to be creating the right queries, but no email or email related errors come up.

I am tempted to just use Ryan Bates' excellent tutorial on beta invites and write it up myself, but I'd love to have something working. We just can't seem to figure it out.

+1  A: 

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

Brian Landau
thanks, you really helped us out alot!
Angela
I've also now put up an example application that may be useful: http://github.com/brianjlandau/acts_as_inviteable_example_app
Brian Landau
Thanks you did an amazing job.
Angela