【发布时间】:2011-04-29 10:39:23
【问题描述】:
这应该很简单,但我一直找不到答案。谁能指出我正确的方向?
我正在实施一个 Rails3 测试版邀请系统,就像 Ryan Bates - http://railscasts.com/episodes/124-beta-invitations
我已设置邮件程序以发送邀请网址。一切正常,除了一个小问题。
mailer生成的url是/user/sign_up.token。
我需要生成 /user/sign_up/token(斜线而不是句点)。
我想我需要更改“Mailer.invitation().deliver”中的语法,但我找不到任何帮助文档。谁能指出我正确的方向?
我的路线文件的相关位:
devise_for :users, :path_prefix => 'registration', :controllers => {:registrations => 'users/registrations'} do
get "registration/users/sign_up/:invitation_token" => "users/registrations#new"
end
邀请控制器:
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
感谢您的任何想法!
【问题讨论】:
标签: ruby-on-rails devise ruby-on-rails-3