Note that there are some explanatory texts on larger screens.

plurals
  1. PORails3 invitations and mailer - how to add variables to routes/urls?
    primarykey
    data
    text
    <p>This should be simple fix, but I've been unable to find an answer. Can anyone point me in the right direction?</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>I've set up the mailer to send out the invite urls. Everything works fine, apart from one small issue.</p> <p>The url generated by the mailer is /user/sign_up.token.</p> <p>I need to generate /user/sign_up/token (slash instead of period). </p> <p>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?</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>Invitations controller:</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>Mailer:</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>Thank you for any ideas!</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.
 

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