I''m new to Rails. I want to make a scaffold to a table. However, the database has a legacy scheme, so I can''t follow the Rails name scheme for the table names. The table I need to scaffold is called "rad_radios". I read somewhere that I could use set_table_name to name the table, like this: set_table_name = "rad_radios". However I getting an error when I want to see the list.rhtml page. It seems it doesn''t set the field names correctly. Also, the id field isn''t called "id", but "rad_id". What do I need to do? Thanks Marcelo Paniagua -- Este correo esta libre de virus!
Marcelo Paniagua wrote:> I''m new to Rails. I want to make a scaffold to a table. However, the > database has a legacy scheme, so I can''t follow the Rails name scheme > for the table > names. The table I need to scaffold is called "rad_radios". I read > somewhere that I could use set_table_name to name the table, like this: > > set_table_name = "rad_radios".set_table_name is a function so you want: set_table_name "rad_radios" or set_table_name("rad_radios") what you were doing is assigning to a local variable
set_table_name is also aliased as table_name=, so you can write: set_table_name "rad_radios" -OR- table_name = "rad_radios" ...the two forms are equivalent. Using set_table_name seems to be more idiomatic in Rails. Cheers, Ken PS - Marcelo, are you testing the Firebird adapter? If yes, how is it working for you?
If the stuff you have already been sent doesn''t work - try putting it in upper case. Firebird loves uppercase. Liz _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Marcelo, Oops... never addressed your second question:> Also, the id field isn''t called "id", but "rad_id". What do I need to do?set_primary_key "rad_id" OR primary_key = "rad_id" Also, if you''re using Firebird, you''ll need a sequence generator to auto-generate primary key values. The default name format is "#{table_name}_seq -- e.g., for your table, it would be "rad_radios_seq". If you''re generator name is different, you''ll need to specify this as well (fill-in your generator name): set_sequence_name "rad_radios_generator" OR sequence_name = "rad_radios_generator" Cheers, Ken
Yes I''m testing the Firebird adapter... I just started this morning... There are several applications here at my office that are done in Firebird... I''m testing the adapter to see If I can migrate some of the application to a web platform. So far is working good... I created some test table to use the adapter and it seems to work fine... I will comment about the actual perfomance once I can pass the table to Rails. later Ken Kunz wrote:>set_table_name is also aliased as table_name=, so you can write: > >set_table_name "rad_radios" > -OR- >table_name = "rad_radios" > >...the two forms are equivalent. Using set_table_name seems to be >more idiomatic in Rails. > >Cheers, >Ken > >PS - Marcelo, are you testing the Firebird adapter? If yes, how is it >working for you? >_______________________________________________ >Rails mailing list >Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >http://lists.rubyonrails.org/mailman/listinfo/rails > > >-- Este correo esta libre de virus!
Still not working... I don''t know if I''m doing something wrong. I''m writting the following code: require "C:\\prueba_firebird\\path-to-your-rails-app\\vendor\\activerecord\\lib\\active_record.rb" ActiveRecord::Base.establish_connection(:adapter => "firebird", :host => "localhost", :database => "C:\\DB\\NRM\\NRM_Mexico.GDB", :username => "sysdba", :password => "masterkey") class Rad_radios < ActiveRecord::Base set_table_name("RAD_RADIOS") set_primary_key("RAD_ID") end test_1 = Rad_radios.find(2) test_1.rad_nombre = "new one" test_1.save but when I run it it tells me: Exception: undefined method `upcase'' for nil:NilClass It seems the object fails to be created ... any idea? Marcelo Paniagua. -- Este correo esta libre de virus!
Marcelo,> Still not working... I don''t know if I''m doing something wrong. I''m > writting the following code:[snip]> class Rad_radios < ActiveRecord::Base > set_table_name("RAD_RADIOS") > set_primary_key("RAD_ID") > endYou need to use a lowercase value for the primary key. Also, if you use the correct ActiveRecord convention for naming your model class, you shouldn''t need to explicitly set the table name. Try it this way: class RadRadio < ActiveRecord::Base set_primary_key "rad_id" end The RadRadio model class will automatically be mapped to the rad_radios table. The Firebird adapter rdoc documentation includes an explanation of how case-mapping is performed between Firebird column names and ActiveRecord attributes. Hope this helps. Ken
Thanks.. I will try this.. I didn''t use the convention ( that I think is very nice) because the database use a legacy schema. Ken Kunz wrote:>Marcelo, > > > >>Still not working... I don''t know if I''m doing something wrong. I''m >>writting the following code: >> >> > >[snip] > > > >>class Rad_radios < ActiveRecord::Base >> set_table_name("RAD_RADIOS") >> set_primary_key("RAD_ID") >>end >> >> > >You need to use a lowercase value for the primary key. Also, if you >use the correct ActiveRecord convention for naming your model class, >you shouldn''t need to explicitly set the table name. Try it this way: > >class RadRadio < ActiveRecord::Base > set_primary_key "rad_id" >end > >The RadRadio model class will automatically be mapped to the rad_radios table. > >The Firebird adapter rdoc documentation includes an explanation of how >case-mapping is performed between Firebird column names and >ActiveRecord attributes. > >Hope this helps. > >Ken >_______________________________________________ >Rails mailing list >Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >http://lists.rubyonrails.org/mailman/listinfo/rails > > >-- Este correo esta libre de virus!