Richard Finegan
2007-Oct-24 23:49 UTC
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: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='' -------------------------- 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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
HI Richard> NoMethodError (undefined method `email_config_id='' forcch: You should focus on whether email_config_id has been defined as a field or elsewhere... CCH http://cch4rails.blogspot.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Bob Showalter
2007-Oct-25 01:53 UTC
Re: NoMethodError when creating new ActiveRecord model object
On 10/24/07, Richard Finegan <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> 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: > > ---------------------- > > 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: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='' > -------------------------- > > 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.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... --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Richard Finegan
2007-Oct-25 02:19 UTC
Re: NoMethodError when creating new ActiveRecord model object
Bob Showalter 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"} [4;36;1mEmailConfig Load (0.000000) [0;1mSELECT * FROM email_configs WHERE (email_configs.id = ''1'') [4;35;1mEmailRecipient Load (0.000000) SELECT * FROM email_recipients WHERE (email_recipients.email_config_id = 1) 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"} [4;36;1mEmailConfig Load (0.015000) [0;1mSELECT * FROM email_configs WHERE (email_configs.id = ''1'') 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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Richard Finegan
2007-Oct-25 02:23 UTC
Re: NoMethodError when creating new ActiveRecord model object
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.comi was hoping ActiveRecord would create it for me, i''m pretty sure i didn''t define it anywhere myself. thanks for your help Richard -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Rick DeNatale
2007-Oct-25 17:31 UTC
Re: NoMethodError when creating new ActiveRecord model object
On 10/24/07, Richard Finegan <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> 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 4I''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/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Richard Finegan
2007-Oct-25 17:49 UTC
Re: NoMethodError when creating new ActiveRecord model object
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. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Rick DeNatale
2007-Oct-25 18:57 UTC
Re: NoMethodError when creating new ActiveRecord model object
On 10/25/07, Richard Finegan <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> 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/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---