I’m trying to simply write to a mysql db from the console.
Model = Entry , table = entries
Problem is my values keep getting turned into instance variables and end
up nil.
Entry.create(:title =>“new title”, :body => “Brand new body”)
=> #<Entry:0x27178c4 @attributes={“body”=>nil, “title”=>nil, “id”=>6},
@body=“Brand new body”, @title=“new title”, @new_record=false,
@errors=#<ActiveRecord::Errors:0x2716d0c @base=#<Entry:0x27178c4 …>,
@errors={}>>
Also tried… >> Entry.create(“title” =>“new title”, “body” => “Brand new
body”)
Any clues?
Other tables in same db are fine…
TIA
Chas
Hmmm…
created another table called “dogs”
created a model dog.rb - “Class Dog”
everything works fine…
Then I migrated down to before Entry / entries (Class - table)
renamed em Entry entrys (Class - table)
no go…
active record wants “entries”…
Hi Chas,
You can always use:
class Entry < ActiveRecord::Base
set_table_name ‘entrys’
end
Using this method you can call your tables whatever you like. Does not
play well with migrations though.
Phil
Chas C. wrote:
Hmmm…
created another table called “dogs”
created a model dog.rb - “Class Dog”
everything works fine…
Then I migrated down to before Entry / entries (Class - table)
renamed em Entry entrys (Class - table)
no go…
active record wants “entries”…
Mat S. wrote:
On Aug 12, 2006, at 12:10 PM, Chas C. wrote:
@errors=#<ActiveRecord::Errors:0x2716d0c @base=#<Entry:0x27178c4 …>,
@errors={}>>
Are body and title the right type in the database? If other models
work I’d think the underlying table is the issue. I’m also going
with this because “id” came back from the db fine, but the other two
didn’t, which makes it seem like the database is throwing it away.
-Mat
Thanks guys, got it sorted out.
On Aug 12, 2006, at 12:10 PM, Chas C. wrote:
@errors=#<ActiveRecord::Errors:0x2716d0c @base=#<Entry:0x27178c4 …>,
@errors={}>>
Are body and title the right type in the database? If other models
work I’d think the underlying table is the issue. I’m also going
with this because “id” came back from the db fine, but the other two
didn’t, which makes it seem like the database is throwing it away.
-Mat