[Rails] actionmailer issues

Jeffrey Moss jeff at opendbms.com
Thu Jan 27 22:21:25 GMT 2005


You need to get used to debugging if you are ever going to make any progress 
unassisted. Try using the "console" script in the scripts directory to debug 
this. You must print the results of inspect in order to see it. Run console, 
load your model with require user, then start debugging:

user = User.find_first("id = 123") [enter]
print user.inspect [enter]
confirmation = user.confirmation.build('id' => rand(Time.now)) [enter]
print confirmation.inspect [enter]

I fixed this code for you, dont forget to call save after you "build" an 
object.

Good luck!

-Jeff

----- Original Message ----- 
From: "Nolan Darilek" <nolan at thewordnerd.info>
To: <rails at lists.rubyonrails.org>
Sent: Thursday, January 27, 2005 2:34 PM
Subject: Re: [Rails] actionmailer issues


> On Wed, Jan 26, 2005 at 06:06:05PM -0700, Jeffrey Moss wrote:
>> Nolan,
>>
>> Why do you use a confirmation_id field as an attr_accessor? Why not juse
>> use an association? I can't see an obvious problem with your code, but I 
>> do
>> the exact same thing, here's how I do it:
>>
>
> I was hesitant because I wasn't sure whether it'd be worth storing a
> confirmation association with each user, especially as it'd be used
> only once, but I'm trying to tweak things to use associations
> now. Here is what I have now:
>
> class User < ActiveRecord::Base
>  has_one :confirmation
> . . .
> end
>
> class Confirmation < ActiveRecord::Base
>  belongs_to :user
> end
>
> My schema:
> CREATE TABLE confirmations(id integer not null primary key, user_id 
> integer not null);
> CREATE TABLE users ( id integer NOT NULL PRIMARY KEY, login varchar 
> default NULL, password varchar default NULL, email varchar not null, valid 
> boolean default false, confirmation_id integer default 0);
>
> And my AccountController#confirm_email:
>  def confirm_email
>    @user = User.find_first("id = #{@params["id"]}")
>    confirmation = @user.confirmation.build(:id => rand(Time.now)) # line 
> 48
> @user.confirmation = confirmation
>    Accounts.deliver_signup_email_confirm(@user)
>  end
>
> My user is created, but its confirmation_id is set to 0, and I receive
> the following error in my logs:
>
> NoMethodError (undefined method `build' for nil:NilClass):
>    /app/controllers/account_controller.rb:48:in `confirm_email'
> . . .
>
> I've also tried creating a Confirmation, assigning its values directly
> then saving it, but I get errors claiming that confirmation.user_id
> can't be NULL (this was when I allowed for NULLs in the schema) so it
> seems that something is trashing that value somewhere and I don't know
> where.
>
> Any ideas about what might be wrong? Furthermore, how can I debug
> this? I'm trying .inspect, but it doesn't seem to appear anywhere in
> my logs.
> _______________________________________________
> Rails mailing list
> Rails at lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails 



More information about the Rails mailing list