Rails3邀请函和邮件程序 - 如何向路径/网址添加变量? [英] Rails3 invitations and mailer - how to add variables to routes/urls?
问题描述
这应该是简单的修复,但是我一直找不到答案。任何人都可以指向正确的方向?
This should be simple fix, but I've been unable to find an answer. Can anyone point me in the right direction?
我正在实施一个Rails3测试版邀请系统,一个Ryan Bates - http://railscasts.com/episodes/124-beta-invitations
I'm implementing a Rails3 beta invite system a la Ryan Bates - http://railscasts.com/episodes/124-beta-invitations
I我设置了邮件发送邀请URL。一切都很好,除了一个小问题。
I've set up the mailer to send out the invite urls. Everything works fine, apart from one small issue.
邮件程序生成的网址是/user/sign_up.token。
The url generated by the mailer is /user/sign_up.token.
我需要生成/ user / sign_up / token(斜线而不是句点)。
I need to generate /user/sign_up/token (slash instead of period).
我想我需要更改Mailer.invitation()。deliver中的语法,但是我找不到任何文档可以帮助。任何人都可以指向正确的方向?
I guess I need to change the syntax in "Mailer.invitation().deliver", but I can't find any documentation to help. Can anyone point me in the right direction?
我的路线文件的相关位:
The relevant bits of my routes file:
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
Mailer:
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
感谢您的任何想法!
推荐答案
不完全确定这是否可以工作,但也可以尝试
Not completely sure if this would work, but maybe try
new_user_registration_url(@invitation.token)
而不是new_user_registration_path。
instead of new_user_registration_path.
另一个(但不是很好)的方法将是
Another (but not a very good) method would be
new_user_registration_url+"/#{@invitation.token}" #substitute path for url maybe
希望这有帮助!
这篇关于Rails3邀请函和邮件程序 - 如何向路径/网址添加变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!