?

Log in

No account? Create an account
entries friends calendar profile adric.net Previous Previous Next Next
Is the data there or not? Seriously, just pick one - nil.enroll(aetheric_username, quantum_class_id)
yljatlhQo'! QIch lo'laltbebej!
adric
adric
Is the data there or not? Seriously, just pick one

Having stumped one nice fellow on #rubyonrails, I inflict this on you all:

I can make a new object, which is then empty. Sure. I run a method to populate the fields which runs fine and debug out some correctfield data. Inspecting or printing the method shows it is still empty, but if I ask politely the data is there (accessors and to_string). But. When I ask it to save the data, it writes out all NULLS, which is wrong and also causes the DB to throw back an error (since some of those fields are Not Null in the schema). Elipsises mine to cut down on the number of times you need to read nil and NULL.
>> @moo.to_s
=> "first last-name was Zen order 27,\n      so we'll call it number 27."
>> @moo.moocash_orders_id
=> 27
>> @moo.inspect
=> "#< MoocashOrder moocash_id: nil, moocash_orders_id: nil, student_fname: nil, ...
 nil, is_paid_up: false, created_at: \"2008-11-06 17:40:30\", updated_at: \"2008-11-06 17:40:30\">"
>> @moo.save
ActiveRecord::StatementInvalid: SQLite3::SQLException: SQL logic error or missing database: 
INSERT INTO "moocash_orders" ("moocash_orders_id", ... "created_at") 
VALUES(NULL, ... NULL, '2008-11-06 17:40:30', '2008-11-06 17:40:30')
ETA: Trying out the scaffold views shows that they really don't work right either... tried and fix some of that (self.id="id") to see if it helps. This also may indicate further misalignment of gnats and crumbs in the sqlite3 RAILS_ENV=test. Also my joins may not be right, although I'm not using them anywhere that I know of. sqlite returns data when I "select * from yen_orders" but rails scaffold just shows buttons or polite nothing...

Tags: ,

4 comments or Leave a comment
Comments
jessica_fae From: jessica_fae Date: November 6th, 2008 08:46 pm (UTC) (Link)
Can you post up some of the view, controller, and model code for the parts in question? It'll help with identifying where the problem is.

First thing that should be done to stop ActiveRecord from spitting out the error is to include some validates presence of statements in the model. Also, the fact that to_s is working means that whatever is defined in the to_s method is working, and in this example it looks like the only thing showing is maybe the first or last name and the objects temporary id.

How is the model defined? It looks like there is an issue with the scripts that are assigning the values to the accessors or the column names in he params hash. I can't really say without seeing the rest of the code from the view and the controller. Make sure that the column names are all reflected accurately in the params and the scripts assigning the data. If you aren't using the form_for method in the view, I recommend using it.
adric From: adric Date: November 6th, 2008 08:59 pm (UTC) (Link)

Thanks for looking at this !

That's all I put into the to_s to keep it short. The attr_readers for two fields also work, although it may not be clear in that snip. There's very little code outside of the model, which was created with generate scaffold. The view and controller are blank. If you want to see more the whole mess is in SVN: https://dev.atlbbs.com/svn/atlbbs/moocash/

The model is at: https://dev.atlbbs.com/svn/atlbbs/moocash/app/models/moocash_order.rb

These links should load up the current version of the files, once you get past any complaints about my SSL certificate :)

I'll add in some (more) verifiers in a bit to see if that helps, thanks!
jessica_fae From: jessica_fae Date: November 6th, 2008 09:22 pm (UTC) (Link)

Re: Thanks for looking at this !

Looks like your scripts to run your assemble data script aren't running because your redefinition of the initialize method has not been uncommented out to allow it to run. So uncomment out the initialize method and all should work fine.
adric From: adric Date: November 6th, 2008 09:30 pm (UTC) (Link)

Re: Thanks for looking at this !

Wow, thanks so much for actually looking at this.

It's commented out because it didn't work and I wanted to make sure that my override of the constructor wasn't causing the problem .. yesterday?

You can chat at me on any network of your choice if that's easier on you ?
4 comments or Leave a comment