0

我一直在寻找应该是一个简单问题的答案。谁能指出我正确的方向,或者至少告诉我我应该寻找什么?

我正在实施一个 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

我感谢任何有助于更好地理解为什么会发生这种情况的指针。

谢谢!

4

1 回答 1

1

第一个问题是您需要new_user_registration_url而不是new_user_registration_path. 网址 = 绝对,路径 = 相对。

您可能需要向我们展示您的路线以帮助解决第二个问题。看起来您的参数被视为一种格式。也许您需要自定义映射?就像是:

match '/users/sign_up/:token' => 'users#sign_up', :as => :new_user_registration

由于您已经设置default_url_options,我希望您能够在邮件视图中调用 url 帮助程序,而不是从控制器传递它。

于 2011-04-27T01:27:23.230 回答