Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6935937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:10:06+00:00 2026-05-27T12:10:06+00:00

Using Ryan Bate’s RailsCasts #124 Beta Invites (as well as the updated rails 3.1

  • 0

Using Ryan Bate’s RailsCasts #124 Beta Invites (as well as the updated rails 3.1 api) as a crutch, I’m trying to put together my first piece of Action Mailer functionality: inviting someone to collaborate with you on a project.

My issue is that the :recipient_email isn’t getting saved in the DB and I can’t see what I’m missing.

config/initializers/setup_mail.rb

ActionMailer::Base.smtp_settings = {
  :address                    => "smtp.gmail.com",
  :port                       => 587,
  :domain                     => 'blah.com',
  :user_name                  => 'gmail username',
  :password                   => 'gmail password',
  :authentication             => 'plain',
  :enable_starttls_auto       => true
}

ActionMailer::Base.register_interceptor(DevelopmentMailInterceptor) if Rails.env.development?

app/models/invitation.rb

class Invitation < ActiveRecord::Base

  email_regex = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i

  attr_accessor :recipient_email

  belongs_to :sender, :class_name => "User", :foreign_key => "sender_id"
  has_one :recipient, :class_name => "User", :foreign_key => "recipient_id"

  validates_presence_of :recipient_email, :on => :create, :message => "can't be blank"
  validates :recipient_email, :format => email_regex
  validate :recipient_is_not_registered

  before_create :generate_token

  def sender_name
    sender.user_name
  end

  def sender_email
    sender.email
  end

  private

    def recipient_is_not_registered 
      exsisting_user = User.find_by_email(recipient_email)
      if exsisting_user
        errors.add :recipient_email, 'is already a member.'
      else
        recipient_email
      end
    end

    def generate_token
      self.token = Digest::SHA1::hexdigest([Time.now, rand].join)
    end

end

app/models/user.rb (minus all the auth stuff)

class User < ActiveRecord::Base
  attr_accessible :invitation_token

  has_many :sent_invitations, :class_name => "Invitation", :foreign_key => "sender_id" 
  belongs_to :invitation

end

app/controller/invitations_controller.rb

class InvitationsController < ApplicationController
  before_filter :authenticate

  def new
    @title = "Invite client"
    @invitation = current_user.sent_invitations.new
  end

  def create
    @invitation = current_user.sent_invitations.create!(params[:invitation])
    sender_name = @invitation.sender_name
    sender_email = @invitation.sender_email
    if @invitation.save
      Mailer.invitation(@invitation, signup_url(@invitation.token), sender_name, sender_email).deliver
      flash[:success] = "Your client has been sent the email. Why not create a booking for them?"
      redirect_to bookings_path
    else
      @title = "Invite client"
      render :new
    end
  end

end

app/mailers/mailer.rb

  def invitation(invitation, signup_url, sender_name, sender_email)
    @signup_url = signup_url
    @sender_name = sender_name
    @sender_email = sender_email
    mail(:to => invitation.recipient_email, 
         :subject => "Invitation to Join",
         :from => @sender_email)
  end  

app/views/invitations/_invitation_form.html.erb

<%= form_for @invitation do |f| %>
    <%= render 'shared/error_messages', :object => f.object %>
    <%= f.hidden_field :email_token %>
    <br />
    <div class="field">
        <%= f.label :recipient_email, "Client's email address" %>
        <%= f.email_field :recipient_email %>
    </div>
    <br />
    <div class="action">
        <%= f.submit "Send invitation", :class => "a small white button radius" %>
    </div>
<% end %>

The SQL log showing that the :recipient_email isn’t getting saved

Started POST "/invitations" for 127.0.0.1 at 2011-12-14 21:27:11 +1100
  Processing by InvitationsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"7/SGZypGXtf9ShlcjC6o8ZRj2Qe4OJTHdjis2/m3ulc=", "invitation"=>{"recipient_email"=>"users@email.com"}, "commit"=>"Send invitation"}
  User Load (0.2ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
   (0.1ms)  BEGIN
  User Load (0.3ms)  SELECT "users".* FROM "users" WHERE "users"."email" = 'users@email.com' LIMIT 1
  SQL (0.4ms)  INSERT INTO "invitations" ("created_at", "recipient_email", "sender_id", "sent_at", "token", "updated_at") VALUES ($1, $2, $3, $4, $5, $6) RETURNING "id"  [["created_at", Wed, 14 Dec 2011 10:27:11 UTC +00:00], ["recipient_email", nil], ["sender_id", 1], ["sent_at", nil], ["token", "56fba1647d40b53090dd49964bfdf060228ecb2d"], ["updated_at", Wed, 14 Dec 2011 10:27:11 UTC +00:00]]
   (10.2ms)  COMMIT
  User Load (0.3ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
   (0.1ms)  BEGIN
  User Load (0.2ms)  SELECT "users".* FROM "users" WHERE "users"."email" = 'users@email.com' LIMIT 1
   (0.1ms)  COMMIT
Rendered mailer/invitation.text.erb (0.4ms)

Sent mail to users@email.com (7ms)
Date: Wed, 14 Dec 2011 21:27:11 +1100
From: admin@email.com
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T12:10:07+00:00Added an answer on May 27, 2026 at 12:10 pm

    It’s probably the attr_accessor :recipient_email line in your Invitation model. Take that line out as recipient_email is a database field, ain’t it?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Ruby on Rails 3.0.8. I'm trying to follow the tutorial by Ryan
I've been following Ryan Bates Railscast on Subdomains http://railscasts.com/episodes/221-subdomains-in-rails-3 and using lvh.me to serve
I'm using ryan bates' plugin nested_form and i have been trying to write my
I'm trying to get some basic authentication/authorization with devise/cancan with Rails. Rather than using
I'm using Rails 2.3.2, and trying to get a nested object form to work
Ryan Dahl recommends using Node.JS behind a reverse proxy (i.e nginx). Well.. what is
I was using Ryan Bates's source code for railscasts #141 in order to create
I'm still trying to get my form working using Ryan Bates Nested_fom plugin. The
I am using Ryan Bate's CanCan gem to define abilities and some basic functionality
I'm using Ryan Bates' excellent scope_builder to conditionally build a new named scope to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.