我一直在寻找一个应该是一个简单问题的答案。任何人都可以指向正确的方向,或者至少告诉我我应该寻找什么?在Rails3邮件程序中添加变量到路径/ url路径
我实现一个Rails3中测试邀请系统一拉瑞恩·贝茨 - 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
我明白任何指针,这将有助于更好地理解为什么发生这种情况。
谢谢!
感谢您的指针。 _url做了诡计。我已将相关路线添加到原始问题。感谢您提供的更多建议。另外,这方面的信息源在哪里?也许我正在寻找API文档的错误部分。 – 2011-04-27 01:34:01
因为我在这里提出了两个问题,我将接受你对第一个问题的回答,并将第二个问题放到它自己的问题中。我欢迎您提供任何建议。 http://stackoverflow.com/questions/5830985/formatting-routes-urls-in-rails-with-devise – 2011-04-29 10:42:20