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

  • SEARCH
  • Home
  • 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 8194191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:44:23+00:00 2026-06-07T04:44:23+00:00

I’m working through Ryan Bates’ Railscast #124: Beta Invitations. I’ve got all the code

  • 0

I’m working through Ryan Bates’ Railscast #124: Beta Invitations. I’ve got all the code in place, but I still two problems.

  1. Sessions don’t persist through the email sending process. For some reason, when a signed
    in user sends an invite to a friend, the app signs out the user.
  2. Signed in users can’t send email. I get an error message
    about having the wrong number of arguments.

I don’t think these two problems are related, but on the off chance they are, I thought I should mention both. Does any one have any ideas why I’m encountering these two problems?

Error message when sending email invite as a signed in user:

    ArgumentError in InvitationsController#create

    wrong number of arguments (0 for 2)
    Rails.root: /*********/MyApp

    Application Trace | Framework Trace | Full Trace
    app/mailers/user_mailer.rb:10:in `invitation'
    app/controllers/invitations_controller.rb:16:in `create'

Controller

class InvitationsController < ApplicationController

  def new
    @invitation = Invitation.new
  end

  def create
    @invitation = Invitation.new(params[:invitation])
    @invitation.sender = current_user
    if @invitation.save
      if current_user?(nil) 
         flash[:notice] = "Thank you, we will notify when we are ready."
         redirect_to root_path       
      else
        UserMailer.invitation.(@invitation, signup_path(@invitation.token)).deliver
        flash[:notice] = "Thank you, invitation sent."
        redirect_to hunts_path 
      end
    else
      render :action => 'new'
    end
  end

end

mailers/User_Mailer.rb. Line 10 is the one that says “def invitation(invitation, signup_path).”

class UserMailer < ActionMailer::Base
  default :from => "********"

  def registration_confirmation(user)
    @user = user
    attachments["rails.png"] = File.read("#{Rails.root}/app/assets/images/rails.png")
    mail(:to => "#{user.name} <#{user.email}>", :subject => "Registered")
  end

  def invitation(invitation, signup_path)
    subject    'Invitation'
    recipients invitation.recipient_email
    body       :invitation => invitation, :signup_url => signup_path
    invitation.update_attribute(:sent_at, Time.now)
  end


end

models/invitation.rb

class Invitation < ActiveRecord::Base

  belongs_to :sender, :class_name => 'User'
  has_one :recipient, :class_name => 'User'

  validates_presence_of :recipient_email
  validate :recipient_is_not_registered
  validate :sender_has_invitations, :if => :sender

  before_create :generate_token
  before_create :decrement_sender_count, :if => :sender

  private

  def recipient_is_not_registered
    errors.add :recipient_email, 'is already registered' if User.find_by_email(recipient_email)
  end

  def sender_has_invitations
    unless sender.invitation_limit > 0
      errors.add_to_base 'You have reached your limit of invitations to send.'
    end
  end

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

  def decrement_sender_count
    sender.decrement! :invitation_limit
  end

end

Routes.rb

resources :users, :invitations
resources :sessions, :only => [:new, :create, :destroy]

match '/signup/',  :to => 'users#new'
match '/signup/:invitation_token', :to => 'users#new'
match '/signin',  :to => 'sessions#new'
match '/signout', :to => 'sessions#destroy'
match '/contact', :to => 'pages#contact'
match '/about',   :to => 'pages#about' 
match '/help',    :to => 'pages#help'

root :to => "pages#home"
match ':controller(/:action(/:id(.:format)))'
  • 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-06-07T04:44:24+00:00Added an answer on June 7, 2026 at 4:44 am

    Alright, so this is causing the Session persistence problem:

    Invitation Model in invitation.rb, relevant parts

    belongs_to :sender, :class_name => 'User'
    [...]
    before_create :decrement_sender_count, :if => :sender
    [...]
    def decrement_sender_count
      sender.decrement! :invitation_limit
    end
    

    After reviewing the logs I saw that the decrement! method somehow thinks it’s funny to update the remember_token in the database as well. Then the remember_token in the cookie
    is not valid anymore. The first ugly workaround I came up with is this:

    def decrement_sender_count
      # sender.decrement! :invitation_limit
      limit = sender.invitation_limit
      sender.update_attributes(:invitation_limit => (limit.to_i-1))      
    end
    

    I’ll ask another question to find out what’s up with ActiveRecord there. See better answer here.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I've got a string that has curly quotes in it. I'd like to replace
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I need to clean up various Word 'smart' characters in user input, including but
I have a text area in my form which accepts all possible characters from

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.