strange error

Added by Oliver Barnes 181 days ago

Hi Andrew,

Thanks very much for writing Lockdown and Classy Inheritance, I'm using them both on a project of mine. Lockdown is working great so far, but I'm having a weird problem with CI, which I'm stuck trying to debug:

I have an Institution that depends_on an :address, and when processing the form I get the following stack trace:

NameError (/Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:275:in `load_missing_constant': uninitialized constant Stonean::ClassyInheritance::ClassMethods::Addres):
    /Library/Ruby/Gems/1.8/gems/lockdown-0.5.12/lib/lockdown/classy-inheritance.rb:130:in `address1='
    /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:467:in `const_missing'
    (eval):1:in `address1='
    /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:2361:in `eval'
    /Library/Ruby/Gems/1.8/gems/lockdown-0.5.12/lib/lockdown/classy-inheritance.rb:130:in `address1='

my models:

class Institution < ActiveRecord::Base
  depends_on :address, :attrs => [:address1, :address2, :neighborhood, :zip, :city, :state, :country, :country_code, :area_code, :phone, :fax, :email, :website ], :dependent => :destroy
end

class Address < ActiveRecord::Base
  belongs_to  :institution
end

the form view:

<% form_for @institution do |f| %>
  <p>
    Address + Contact<br />
    address: <%= f.text_field :address1 %><br>
    address2: <%= f.text_field :address2 %><br>
    zip: <%= f.text_field :zip %><br>
    city: <%= f.text_field :city %><br>
    state: <%= f.text_field :state %><br>
    country: <%= f.text_field :country %><br>
    area code: <%= f.text_field :area_code %><br>
    phone: <%= f.text_field :phone %><br>
    fax: <%= f.text_field :fax %><br>
    email: <%= f.text_field :email %><br>
    website: <%= f.text_field :website %><br>
  </p>
<% end %>

at first it seemed to barf with the :address attribute, going into an endless loop when trying to eval it; and so I changed it to :address1, which now gives me this error.

any ideas of what could be causing this?

thanks in advance,
Oliver


Replies

RE: strange error - Added by Andrew Stone 181 days ago

Before we dig into CI, try modifying your Address model and add:


  class Address < ActiveRecord::Base
    set_table_name :addresses
    belongs_to :institution
  end
If that doesn't do the trick, this should:

class Institution < ActiveRecord::Base
  depends_on :address, 
             :attrs => [:address1, :address2, :neighborhood, 
                        :zip, :city, :state, :country, :country_code, 
                        :area_code, :phone, :fax, :email, :website ], 
             :dependent => :destroy, 
             :class_name => "Address" 
end

Let me know if either of these does the trick. I expect the second one is the one you need, but have run into issues with the first (only with an Address model).

thanks for using both projects! cool.