[Rails] ActiveRecord new method can't find attributes

Curt Sampson cjs at cynic.net
Mon Nov 29 07:57:00 GMT 2004


I'm probably a bit slow today, and I get the feeling I must be doing
something completely stupid here. Here's some pretty darn simple code,
using a postgresql connection:

    require 'active_record'

    class Restaurant < ::ActiveRecord::Base

	def self.table_name
	    self.name.gsub(/.*::/, '').downcase
	end

	def self.primary_key
	    table_name + "_id"
	end

    end

    class TC_Restaurant < Test::Unit::TestCase

	def setup
	    super
	    ::ActiveRecord::Base.establish_connection(
		$db_connection_factory.params['olap'].activerecord_spec)
	    ::ActiveRecord::Base.connection.execute(
		"SET search_path TO 'unit_test_tabemo_olap'")
	end

	def test_load
	    restaurant = Restaurant.find(42);
	    assert_not_nil(restaurant)
	    assert_equal("42", restaurant.id)
	    assert_equal('The Test Restaurant', restaurant.restaurant_desc)
	end

	def test_create
	    restaurant = Restaurant.new('restaurant_id' => 43,
		'restaurant_desc' => 'created')
	end

    end

Reading works just fine. However, I can't create a new Restaurant:

      1) Error:
    test_create(TC_Restaurant):
    NoMethodError: undefined method `restaurant_desc=' for #<Restaurant:0x8523a6c>
	/u/cjs/tabemo/install/lib/ruby/active_record/base.rb:817:in `method_missing'
	/u/cjs/tabemo/install/lib/ruby/active_record/base.rb:712:in `send'
	/u/cjs/tabemo/install/lib/ruby/active_record/base.rb:712:in `attributes='
	/u/cjs/tabemo/install/lib/ruby/active_record/base.rb:711:in `each'
	/u/cjs/tabemo/install/lib/ruby/active_record/base.rb:711:in `attributes='
	/u/cjs/tabemo/install/lib/ruby/active_record/base.rb:624:in `initialize_without_callbacks'
	/u/cjs/tabemo/install/lib/ruby/active_record/callbacks.rb:212:in `initialize'
	/u/cjs/tabemo/mobile-website/ruby/lib/tabemo/db/restaurant.rb:37:in `new'
	/u/cjs/tabemo/mobile-website/ruby/lib/tabemo/db/restaurant.rb:37:in `test_create'

What's am I doing wrong here?

cjs
-- 
Curt Sampson  <cjs at cynic.net>   +81 90 7737 2974   http://www.NetBSD.org
     Make up enjoying your city life...produced by BIC CAMERA


More information about the Rails mailing list