Saturday, June 11, 2011

Re: [Rails] after initialize blowing up---help

On 11 June 2011 09:45, ddoherty03 <ddoherty03@gmail.com> wrote:
> All,
> Can anyone see what's happening here?
> ================== migration =======================
> class CreateGreetings < ActiveRecord::Migration
>   def self.up
>     create_table :greetings do |t|
>       t.string :greet
>       t.string :language
>       t.integer :count
>       t.timestamps
>     end
>   end
>   def self.down
>     drop_table :greetings
>   end
> end
> ================== greeting.rb =============================
> class Greeting < ActiveRecord::Base
>   after_initialize :check_greet
>   validates_uniqueness_of :count
>   def check_greet
>     self.language = lanugage.capitalize
>   end
> end
> =================== greeting.yml ==========================
> hello:
>   greet: howdy
>   language: english
>   count: 44
> hola:
>   greet: hola, que tal
>   language: spanish
>   count: 55
> =================== greeting_test.rb ========================
> require 'test_helper'
> class GreetingTest < ActiveSupport::TestCase
>   # Replace this with your real tests.
>   test "uniqueness of count" do
>     gg = Greeting.new(:language => 'esperanto', :count =>
> greetings(:hello).count)
>     assert !gg.valid?
>   end
> end
> =========================================================
> When I run 'rake test:units' on this it blows up when getting to the
> after_initialize
> procedure, claiming there is no method 'language' for the Greeting class.
> I'm having this issue in a larger app, but I've tried to pare this down to
> the minimum
> that reproduces the problem.

Have you run the migration?

What does db/schema.rb show for the greetings table?

Colin

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate