Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding variables to routes/ url paths in Rails3 mailer
    primarykey
    data
    text
    <p>I've been searching for an answer to what should be a simple question. Can anyone point me in the right direction, or at least tell me what I should be searching for?</p> <p>I'm implementing a Rails3 beta invite system a la Ryan Bates - <a href="http://railscasts.com/episodes/124-beta-invitations" rel="nofollow">http://railscasts.com/episodes/124-beta-invitations</a></p> <p>The mailer generates a relative link. How to I preprend the host path? (I already have config.action_mailer.default_url_options set up in development.rb)</p> <p>-- The relevant bits of my routes file.</p> <pre><code>devise_for :users, :path_prefix =&gt; 'registration', :controllers =&gt; {:registrations =&gt; 'users/registrations'} do get "registration/users/sign_up/:invitation_token" =&gt; "users/registrations#new" end </code></pre> <p>I've made some minor adjustments to reflect updates in Rails and to play nicely with Devise. The controller now looks like this</p> <pre><code>class InvitationsController &lt; 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 =&gt; "Thank you, your friend will receive their invitation soon." else redirect_to root_url, :notice =&gt; "Thank you, we'll let you know when the next batch of invites are availale." end else if current_user.invitation_limit &gt; 0 render :action =&gt; 'new', :alert =&gt; "Sorry, there was a problem! Please try a again." else redirect_to root_url, :alert =&gt; "Sorry, you don't have any invitations left. Please wait until we issue more." end end end end </code></pre> <p>And the mailer like this:</p> <pre><code>class Mailer &lt; 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 </code></pre> <p>I appreciate any pointers that would help be better understand why this is happening.</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload