Hi all I''m new to both Ruby and Rails. I am trying to reference a Ruby class (non AR) from my view. I am getting the following error: undefined method `name'' for #<DbTable:0x23e4a4c @name="sqlite_sequence"> dbtable.rb =======class DbTable attr_reader :name def initialize(name) @name = name end end database_controller.rb ===============require ''sqlite3'' class DatabaseController < ApplicationController def index @databases = Database.find(:all) end def list @tables = Array.new database = Database.find(@params[:id]) db = SQLite3::Database.new( database.path ) db.execute( "select * from sqlite_master where type = ''table'';" ) do |row| aTable = DbTable.new(row[1]) @tables << aTable end end end list.rhtml =====<% for t in @tables %> <%= t.name <http://t.name> %><br/> <% end %> For the life of me, I can''t figure out what I''m missing. When I create a DbTable from the console, I can access the name property. Thanks in advance for the assist! Todd Breiholz _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Are you requiring dbtable.rs anywhere? Like the controller? Try that, or require_dependency. Todd Breiholz wrote:> Hi all > > I''m new to both Ruby and Rails. I am trying to reference a Ruby class > (non AR) from my view. I am getting the following error: > > undefined method `name'' for #<DbTable:0x23e4a4c @name="sqlite_sequence"> > > dbtable.rb > =======> class DbTable > attr_reader :name > > def initialize(name) > @name = name > end > end > > database_controller.rb > ===============> require ''sqlite3'' > > class DatabaseController < ApplicationController > > def index > @databases = Database.find(:all) > end > > def list > @tables = Array.new > database = Database.find (@params[:id]) > db = SQLite3::Database.new( database.path ) > db.execute( "select * from sqlite_master where type = > ''table'';" ) do |row| > aTable = DbTable.new(row[1]) > @tables << aTable > end > end > end > > list.rhtml > =====> <% for t in @tables %> > <%= t.name <http://t.name> %><br/> > <% end %> > > > For the life of me, I can''t figure out what I''m missing. When I > create a DbTable from the console, I can access the name property. > > Thanks in advance for the assist! > > Todd Breiholz > >------------------------------------------------------------------------ > >_______________________________________________ >Rails mailing list >Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >http://lists.rubyonrails.org/mailman/listinfo/rails > >
Hmm. I was sure I tried that, but I put a require ''dbtable'' in the controller and now it works. Thanks for the help Steve! Todd On 8/12/05, Steve Downey <sldowney-TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org> wrote:> > Are you requiring dbtable.rs anywhere? Like the controller? Try that, > or require_dependency. > >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Shouldn''t that be DbTable.new(row[0])? Try tossing an "inspect t" or "p t" in there as well, to get some debug output. Todd Breiholz wrote:> Hi all > > I''m new to both Ruby and Rails. I am trying to reference a Ruby class > (non AR) from my view. I am getting the following error: > > undefined method `name'' for #<DbTable:0x23e4a4c @name="sqlite_sequence"> > > dbtable.rb > =======> class DbTable > attr_reader :name > > def initialize(name) > @name = name > end > end > > database_controller.rb > ===============> require ''sqlite3'' > > class DatabaseController < ApplicationController > > def index > @databases = Database.find(:all) > end > > def list > @tables = Array.new > database = Database.find (@params[:id]) > db = SQLite3::Database.new( database.path ) > db.execute( "select * from sqlite_master where type = ''table'';" > ) do |row| > aTable = DbTable.new(row[1]) > @tables << aTable > end > end > end > > list.rhtml > =====> <% for t in @tables %> > <%= t.name <http://t.name> %><br/> > <% end %> > > > For the life of me, I can''t figure out what I''m missing. When I create > a DbTable from the console, I can access the name property. > > Thanks in advance for the assist! > > Todd Breiholz >
Actually, I should be more specific in my select (select name from sqlite_master...). Then it would be row[0]. Thanks for the debugging tips, though! On 8/12/05, Wilson <defiler-ifvz4xmYPRU@public.gmane.org> wrote:> > Shouldn''t that be DbTable.new(row[0])? > Try tossing an "inspect t" or "p t" in there as well, to get some debug > output. > >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails