(posted also at http://railsforum.com/viewtopic.php?pid=2162)
hi, my second app, both in the early stages. for this one it is an
already-existing database, no surrogate key, and the name of the table
does fit the default. so here’s the DDL:
CREATE TABLE APP_CONF (
CONF_KEY varchar(64) not null,
CONF_VALUE varchar(256) null,
CONF_GROUP varchar(32) null,
CONF_GROUP_ORDER numeric(4) null,
constraint CONF_KEY primary key (CONF_KEY)
);
and i created the scaffolding:
C:\workspace\spc>ruby script/generate scaffold AppConf Admin
exists app/controllers/
…
dependency model
exists app/models/
…
create app/views/admin/_form.rhtml
create app/views/admin/list.rhtml
create app/views/admin/show.rhtml
create app/views/admin/new.rhtml
create app/views/admin/edit.rhtml
create app/controllers/admin_controller.rb
…
modified the model (app_conf.rb):
class AppConf < ActiveRecord::Base
set_table_name “app_conf”
set_primary_key “conf_key”
end
cranked up the server and blah - i get entries for all the rows, but all
the attributes within those rows are nil. the defaultrhtml that iterates
through the attributes gets nils for all of them.
if i run the console, i see the same sort of thing:
C:\workspace\spc>ruby script/console
Loading development environment.
<?xml version="1.0" encoding="UTF-8"?> [email protected] webmasterEmail => nil >> puts x.conf_key nil => nil >>x = AppConf.find(‘webmasterEmail’)
=> #<AppConf:0x37cd834 @attributes={“CONF_VALUE”=>“[email protected]”,
“CONF_GROUP_ORDER”=>nil, “CONF_GROUP”=>nil,
“CONF_KEY”=>“webmasterEmail”}>
puts x.to_xml
so i am getting the data, but what i thought (and what the
scaffold-generator thought) was the way to access the individual
attributes doesn’t work.
i am new at this, so i know it’s something i am forgetting to do, i’d
appreciate someone telling me what that is.
thanks
john