NoMethodError when creating new ActiveRecord model object

the strangest thing is happening…i’m not getting this every time,
maybe 1/3 of the time, identical requests…

i’m a rails newbie, but i think i’m trying pretty standard stuff, this
is an excerpt from the log:


Processing EmailConfigsController#edit_xml (for 127.0.0.1 at 2007-10-24
15:52:09) [GET]
Session ID: 6630219819a2da423d8c48a259dd28d6
Parameters: {“action”=>“edit_xml”, “id”=>“1”,
“controller”=>“email_configs”}
←[4;36;1mEmailConfig Load (0.000000)←[0m ←[0;1mSELECT * FROM
email_configs WHERE (email_configs.id = ‘1’) ←[0m

NoMethodError (undefined method email_config_id=' for #<EmailRecipient:0x463caa0 @new_record=true, @attributes={}>): c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.4/lib/active_record/base.rb:1860:inmethod_missing’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.4/lib/active_record/base.rb:1675:in
send' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.4/lib/active_record/base.rb:1675:inattributes=’

in my controller:

def edit_xml()
@email_config = EmailConfig.find(params[:id])
@email_recipient = EmailRecipient.new(:email_config_id =>
@email_config.id)
render :xml => @email_config.to_xml(:dasherize => false, :include => [
:email_recipients ])
end


my models:

class EmailConfig < ActiveRecord::Base
has_many :email_recipients
validates_presence_of :name, :from, :subject, :template
end

class EmailRecipient < ActiveRecord::Base
belongs_to :email_config
validates_presence_of :send_as, :email
end


my tables:

db2 => describe table whitecap.email_configs

Column Type Type
name schema name Length
Scale Nulls



ID SYSIBM INTEGER 4
0 No
NAME SYSIBM VARCHAR 128
0 No
FROM SYSIBM VARCHAR 64
0 No
SUBJECT SYSIBM VARCHAR 128
0 No
TEMPLATE SYSIBM VARCHAR 128
0 No

5 record(s) selected.

db2 => describe table whitecap.email_recipients

Column Type Type
name schema name Length
Scale Nulls



ID SYSIBM INTEGER 4
0 No
EMAIL_CONFIG_ID SYSIBM INTEGER 4
0 No
SEND_AS SYSIBM VARCHAR 3
0 No
EMAIL SYSIBM VARCHAR 128
0 No

4 record(s) selected.


if anyone has any ideas, thanks! i’m going nuts trying to figure this
out.

Richard

HI Richard

NoMethodError (undefined method `email_config_id=’ for

cch: You should focus on whether email_config_id has been defined as a
field or elsewhere…

CCH

On 10/24/07, Richard F. [email protected] wrote:

15:52:09) [GET]
`method_missing’
@email_config = EmailConfig.find(params[:id])
class EmailConfig < ActiveRecord::Base

ID SYSIBM INTEGER 4
5 record(s) selected.
EMAIL_CONFIG_ID SYSIBM INTEGER 4
0 No
SEND_AS SYSIBM VARCHAR 3
0 No
EMAIL SYSIBM VARCHAR 128
0 No

4 record(s) selected.

I’m just guessing here, but perhaps something is going wrong when AR
is trying to get the list of columns for the table. Look at the log in
more detail. From the point of the crash, look backward until you find
a line starting with “Processing”. That’s the start of your request.
Now look forward and see if you can identify where AR is getting the
field list.

Here’s an example from one of my logs (I’m using MySQL, not DB2):

Param Columns (0.004356) SHOW FIELDS FROM params

AR does this in order to figure out which field accessors to create.
Your table has a “email_config_id” column, so it should create the
accessor. Maybe by looking at the logs for a good request and a bad
request you can see something different…

Bob S. wrote:

I’m just guessing here, but perhaps something is going wrong when AR
is trying to get the list of columns for the table. Look at the log in
more detail. From the point of the crash, look backward until you find
a line starting with “Processing”. That’s the start of your request.
Now look forward and see if you can identify where AR is getting the
field list.

Here’s an example from one of my logs (I’m using MySQL, not DB2):

Param Columns (0.004356) SHOW FIELDS FROM params

AR does this in order to figure out which field accessors to create.
Your table has a “email_config_id” column, so it should create the
accessor. Maybe by looking at the logs for a good request and a bad
request you can see something different…

thanks for your help…for whatever reason, i don’t see rails attempt to
read the column…i actually originally started this app using mysql so
i’ve witnessed the “show fields” line as well…anyway this is the first
line i see involving email_recipients:

SELECT * FROM email_recipients WHERE (email_recipients.email_config_id =
1

this time i tried to recreate it it bombed on the 11th try…here’s a
sample good entry:

Processing EmailConfigsController#edit_xml (for 127.0.0.1 at 2007-10-24
19:07:21) [GET]
Session ID: 6f1d459f31b687f86d967058071b9ef5
Parameters: {“action”=>“edit_xml”, “id”=>“1”,
“controller”=>“email_configs”}
e[4;36;1mEmailConfig Load (0.000000)e[0m e[0;1mSELECT * FROM
email_configs WHERE (email_configs.id = ‘1’) e[0m
e[4;35;1mEmailRecipient Load (0.000000)e[0m e[0mSELECT * FROM
email_recipients WHERE (email_recipients.email_config_id = 1) e[0m
Completed in 0.06200 (16 reqs/sec) | Rendering: 0.00000 (0%) | DB:
0.00000 (0%) | 200 OK [http://localhost/email_configs/edit_xml/1]

here’s the bomb:

Processing EmailConfigsController#edit_xml (for 127.0.0.1 at 2007-10-24
19:07:29) [GET]
Session ID: 6f1d459f31b687f86d967058071b9ef5
Parameters: {“action”=>“edit_xml”, “id”=>“1”,
“controller”=>“email_configs”}
e[4;36;1mEmailConfig Load (0.015000)e[0m e[0;1mSELECT * FROM
email_configs WHERE (email_configs.id = ‘1’) e[0m

NoMethodError (undefined method email_config_id=' for #<EmailRecipient:0x465b34c @new_record=true, @attributes={}>): c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.4/lib/active_record/base.rb:1860:in method_missing’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.4/lib/active_record/base.rb:1675:in
send' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.4/lib/active_record/base.rb:1675:in attributes=’

i’m baffled…maybe i’ll switch it back to mysql and see if it happens
there.

thanks again, any other ideas let me know

Richard

CCH wrote:

HI Richard

NoMethodError (undefined method `email_config_id=’ for

cch: You should focus on whether email_config_id has been defined as a
field or elsewhere…

CCH
http://cch4rails.blogspot.com

i was hoping ActiveRecord would create it for me, i’m pretty sure i
didn’t define it anywhere myself.

thanks for your help

Richard

Rick Denatale wrote:

my tables:

db2 => describe table whitecap.email_recipients

EMAIL_CONFIG_ID SYSIBM INTEGER 4

I’ve never used the db2 adapter, but is there perhaps a case
sensitivity issue in play here?

What happens if in script/console you enter EmailRecipient.column_names


Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

EmailRecipient.column_names
=> [“id”, “email_config_id”, “send_as”, “email”]

the bombing doesn’t happen all the time, just 1/3 to 1/4 of the time…

thanks for your help

Richard F.

On 10/25/07, Richard F. [email protected] wrote:

Rick Denatale wrote:

What happens if in script/console you enter EmailRecipient.column_names

EmailRecipient.column_names
=> [“id”, “email_config_id”, “send_as”, “email”]

the bombing doesn’t happen all the time, just 1/3 to 1/4 of the time…

Strange! If you figure this out, please let us know. Sorry but I’m
out of ideas at the moment.


Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

On 10/24/07, Richard F. [email protected] wrote:

the strangest thing is happening…i’m not getting this every time,
maybe 1/3 of the time, identical requests…

i’m a rails newbie, but i think i’m trying pretty standard stuff, this
is an excerpt from the log:


NoMethodError (undefined method `email_config_id=’ for
#<EmailRecipient:0x463caa0 @new_record=true, @attributes={}>):


my tables:

db2 => describe table whitecap.email_recipients

EMAIL_CONFIG_ID SYSIBM INTEGER 4

I’ve never used the db2 adapter, but is there perhaps a case
sensitivity issue in play here?

What happens if in script/console you enter EmailRecipient.column_names


Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/