【问题标题】:Acts_as_Inviteable Plugin not sending out invites in Ruby on RailsActs_as_Inviteable 插件未在 Ruby on Rails 中发送邀请
【发布时间】:2010-01-14 19:00:48
【问题描述】:

我一直在尝试创建每个现有用户都可以发送的 beta 邀请,并希望能够使用一个名为 acts_as_inviteable http://github.com/brianjlandau/acts_as_inviteable 的插件

我想知道是否有人对此有直接经验。当我检查控制台时,它似乎正在创建正确的查询,但没有出现电子邮件或与电子邮件相关的错误。

我很想使用 Ryan Bates 的关于 beta 邀请的优秀教程并自己编写它,但我很想有一些工作。我们似乎无法弄清楚。

【问题讨论】:

标签: ruby ruby-on-rails-plugins


【解决方案1】:

您需要解决许多问题:

将此行添加到您的配置块之一(在environment.rbconfig/environment 中的每个文件中):

config.action_mailer.default_url_options = {:host => 'somewhere.com'}

在第 3 行的 app/models/invitation.rb 中,您已调用 attr_accessible :recipient_email,这将阻止您批量分配发件人。你应该把它改成这样:

attr_accessible :recipient_email, :sender, :sender_id

invitations_controller.rb 也应该是这样的:

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

除非您已登录,否则您确实无法发送邀请(因为您需要一个发件人,在这种情况下是current_analyst 而不是@current_user),因此根据登录情况,这些行具有不同的逻辑或未删除。

此外,邀请模型将自动发送电子邮件,因此无需调用Mailer.deliver_invitation(@invitation, signup_url(@invitation.token))(实际上它必须是AnalystInvitationMailer.deliver_invitation(@invitation)

您可以在此处查看完整的工作补丁:http://gist.github.com/290911

【讨论】:

猜你喜欢
  • 2012-01-03
  • 2013-06-08
  • 1970-01-01
  • 2011-12-21
  • 2012-07-19
  • 2011-04-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多