我一直在寻找应该是一个简单问题的答案。谁能指出我正确的方向,或者至少告诉我我应该寻找什么?
我正在实施一个 Rails3 beta 邀请系统,就像 Ryan Bates - http://railscasts.com/episodes/124-beta-invitations
邮件程序生成一个相对链接。如何预先设置主机路径?(我已经在 development.rb 中设置了 config.action_mailer.default_url_options)
-- 我的路线文件的相关位。
devise_for :users, :path_prefix => 'registration', :controllers => {:registrations => 'users/registrations'} do
get "registration/users/sign_up/:invitation_token" => "users/registrations#new"
end
我做了一些小的调整以反映 Rails 中的更新并与 Devise 很好地配合使用。控制器现在看起来像这样
class InvitationsController < ApplicationController
def new
@invitation = Invitation.new
@title = "Invite a friend"
end
def create
@invitation = Invitation.new(params[:invitation])
@invitation.sender = current_user
if @invitation.save
if user_signed_in?
Mailer.invitation(@invitation, new_user_registration_path(@invitation.token)).deliver
redirect_to root_url, :notice => "Thank you, your friend will receive their invitation soon."
else
redirect_to root_url, :notice => "Thank you, we'll let you know when the next batch of invites are availale."
end
else
if current_user.invitation_limit > 0
render :action => 'new', :alert => "Sorry, there was a problem! Please try a again."
else
redirect_to root_url, :alert => "Sorry, you don't have any invitations left. Please wait until we issue more."
end
end
end
end
和这样的邮件:
class Mailer < ActionMailer::Base
def invitation(invitation, sign_up)
subject 'Invitation'
recipients invitation.recipient_email
@greeting = "Hi"
@invitation = invitation
@signup_url = sign_up
@sender = invitation.sender_id
invitation.update_attribute(:send_at, Time.now)
end
end
我感谢任何有助于更好地理解为什么会发生这种情况的指针。
谢谢!