i've been playing with ror for a little over two months now, and was
wondering wether someone could explain to me what was
cattr_accessor
and if it is still in use. . . i looked up in api.rubyonrails.com and
coulnd't find any documentation...
is it a useful/worth learning method? what do u use it for?
--
Posted via http://www.ruby-forum.com/.
thanks!
My ruby script is throwing the following error when I try to run it. I
thought it was a path problem and did a completely new install. Does
anyone know why I would be getting this error.
I've also pasted a copy of the script below.
$ruby script.rb
/usr/local/lib/ruby/site_ruby/1.8/active_record/base.rb:246: undefined
method `cattr_accessor' for ActiveRecord::Base:Class (NoMethodError)
from
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
`require'
from /usr/local/lib/ruby/site_ruby/1.8/active_record.rb:37
from ./db.rb:1
from script.rb:3
Script:
#! /usr/bin/env ruby
$: << '/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib'
require 'db'
require 'activerecord'
require 'config'
require 'faster_csv'
file_dir = File.dirname(__FILE__) + '/files/'
list_of_files = 'files.txt'
unless (ARGV.empty?)
files = ARGV
else
files = IO.readlines(list_of_files)
files.collect!{|file| file.strip}
end
files.each do |filename|
filename = file_dir + filename.strip
puts "Using filename: #{filename}"
unless ( File.exist?( filename ) )
puts "ERROR: #{filename} not found"
else
FasterCSV.foreach(filename) do |row|
tbl_type = row[0]
print "Inserting into #{tbl_type}... "
tbl_info = $field_map[tbl_type]
unless ( tbl_info.nil? )
field_no = tbl_info[:count]
object = tbl_info[:object]
columns = nil
eval %{columns = #{object}.column_names}
#print row.size, ' - ', columns.size, "\n"
if (row.size == columns.size - 1)
new_record = Hash.new
j=0
row.each do |val|
new_record[columns[j+1]] = val
j = j + 1
end
eval %{#{object}.create(new_record)}
puts "done"
else
puts "FAILED"
end
else
puts 'ERROR: Table not found'
end
end
end
end
> def x # read "attribute" (i.e., value of instance variable)
On Fri, 5 Sep 2008, Jason Lillywhite wrote:
>
> It seems odd that cattr_* is not in the native Ruby and that you have to
> require active support and rubygems to get this to work. Why is this not
> built in the native Ruby source?
See my answer on ruby-talk.
David
--
Rails training from David A. Black and Ruby Power and Light:
Intro to Ruby on Rails January 12-15 Fort Lauderdale, FL
Advancing with Rails January 19-22 Fort Lauderdale, FL *
* Co-taught with Patrick Ewing!
See http://www.rubypal.com for details and updates!