0

私は単純な質問であるべきものに対する答えを探していました。誰かが私を正しい方向に向けることができますか、または少なくとも私が何を探しているべきかを教えてくれますか?

Ryan Bates の Rails3 ベータ招待システムを実装しています - http://railscasts.com/episodes/124-beta-invitations

メーラーは相対リンクを生成します。ホスト パスを先頭に追加するにはどうすればよいですか? (私はすでに config.action_mailer.default_url_options を development.rb に設定しています)

-- 私のルートファイルの関連ビット。

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. URL = 絶対パス、パス = 相対パス。

2 番目の問題を解決するには、ルートを表示する必要がある場合があります。パラメータがフォーマットとして扱われているようです。おそらく、カスタム マッピングが必要ですか? 何かのようなもの:

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

を設定したのでdefault_url_options、コントローラーから渡すのではなく、メーラー ビューで URL ヘルパーを呼び出すことができると思います。

于 2011-04-27T01:27:23.230 に答える