Topic: attribute accessors not accessing

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.
>> x = AppConf.find('webmasterEmail')
=> #<AppConf:0x37cd834 @attributes={"CONF_VALUE"=>"help@my.org", "CONF_GROUP_ORDER"=>nil, "CONF_GROUP"=>nil, "CONF_KEY"=>"webmasterEmail"}>
>> puts x.to_xml
<?xml version="1.0" encoding="UTF-8"?>
<app-conf>
  <CONF-VALUE>help@my.org</CONF-VALUE>
  <CONF-KEY>webmasterEmail</CONF-KEY>
  <CONF-GROUP-ORDER></CONF-GROUP-ORDER>
  <CONF-GROUP></CONF-GROUP>
</app-conf>
=> nil
>> puts x.conf_key
nil
=> nil
>>

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

Re: attribute accessors not accessing

Mhh, you're not showing what doesn't work... Everything you showed works just fine.
Two random thoughts: Ruby interprets the all-caps attribute names as constants and not object fields? Or you're getting the capitalization incorrect. Have you tried using lower-case attribute names for access?
   Thorsten

Re: attribute accessors not accessing

you're right, it's case sensitive:
>> puts x.conf_key
nil
=> nil
>> puts x.CONF_KEY
webmasterEmail
=> nil

i still don't see why the default rails scaffold code fails. i would have expected it to introspect and 'know' what the attributes are. is there something else i need to add to have it do that? as i thought i'd impled before, i have no control over the database schema.

again, thanks.

Re: attribute accessors not accessing

What do you mean by "i still don't see why the default rails scaffold code fails. i would have expected it to introspect and 'know' what the attributes are."? Seem sto work fine to me. Please post an example of what doesn't work.

BTW, the following code in your example uses incorrect capitalization of the table name and the primary key:

class AppConf < ActiveRecord::Base
  set_table_name "app_conf"
  set_primary_key "conf_key"
end

Re: attribute accessors not accessing

again, thanks for the reply. right now i suspect that the database driver may be the culprit. it's the SqlAnywhere one that someone contributed some time ago (and is no longer maintaining). i will set up a quick mysql version to verify, and post back what i am seeing.

what i meant by "i still don't see why the default rails scaffold code fails. i would have expected it to introspect and 'know' what the attributes are" is that i assume that rails builds an active-record that maps the persistent attributes to and from the database. so if the whole thing is built around introspection, i'd expect what is introspected in one place should also be in another, i.e. if my code:
  puts x.CONF_KEY
returns a value, then rails should be able to build a crud that introspects the model to get the method CONF_KEY and use that -- i am probably not explaining this well, i know.