开发者

Acts_as_Inviteable Plugin not sending out invites in Ruby on Rails

I have been trying to create beta invites that each existing user can send out and was hop开发者_运维百科ing 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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜