[Rails] actionmailer issues
Nolan J. Darilek
nolan at thewordnerd.info
Thu Jan 27 00:13:06 GMT 2005
Thanks to those of you who assisted with my FAQ problem
yesterday. Using the form_tag helper resolved the issues nicely.
Now I'm having issues with actionmailer. Authentication works fine,
but now I'd like to add email confirmation. I'm emailing out a random
integer as a confirmation code, and have a Conformation model mapping
the integers to IDs in the users table. Here's my actionmailer model:
class Accounts < ActionMailer::Base
def signup_email_confirm(user)
@user = user
@recipients = @user.email
@from = "accounts at myapp.net"
@subject = "Confirm email address"
@body["confirmation_id"] = @user.confirmation_id
end
end
. . . The relevant code from the user model:
class User < ActiveRecord::Base
attr_accessor :confirmation_id
. . .
end
. . . The portion of my account_controller that sends out the mail:
class AccountController < ApplicationController
model :user, :confirmation
. . .
def confirm_email
c = {}
c["user_id"] = @params["id"]
confirmation = Confirmation.new(c)
confirmation.id = rand(Time.now)
confirmation.save
@user = User.find_first("id = #{@params["id"]}")
@user.confirmation_id = confirmation.id
Accounts.deliver_signup_email_confirm(@user)
end
. . .
end
and the signup_email_confirm.rhtml:
Thanks for signing up! You're almost done.
Before your account is activated, you must visit the following URL:
http://myapp.net/account/confirm/<%= @confirmation_id %>
Your account will then be active, and you can log in using the
username and password you specified.
Unfortunately, @confirmation_id seems to be entirely blank, because
despite receiving the emails, there's nothing after the /confirm
action. The confirmations are being created and look fine, they just
aren't being included in the email.
Thoughts?
More information about the Rails
mailing list