Hi all,
I get a really strange error... I have 2 simple models:
class Membre < ActiveRecord::Base has_one :adhesion end
class Adhesion < ActiveRecord::Base belongs_to :membre end
The relation works well in the console. I can find a Membre and get its Adhesion, or find an Adhesion and get the Member.
Now in a controler/view... If I find like this:
@adhesion = Adhesion.find_by_membre_id(id)
I can use @adhesion in the view without any problem.
But if I do: @adhesion = Membre.find(id).adhesion (what is more clean and logical)
I get an error in the view, as soon as I try to read any field/method of @adhesion.
What confuses me is that in both cases, the content of @adhesion is the same in the view:
#<Adhesion id: 1, membre_id: 51, type: nil, date_adhesion: nil, date_expiration: nil, created_at: "2009-01-06 14:21:06", updated_at: "2009-01-06 14:21:06">
#<Adhesion id: 1, membre_id: 51, type: nil, date_adhesion: nil, date_expiration: nil, created_at: "2009-01-06 14:21:06", updated_at: "2009-01-06 14:21:06">
The failing view:
<%= @adhesion.inspect %> <%= if @adhesion.date_adhesion.nil? # line 9 is here # "You don't have adhesion." %>
The error: You have a nil object when you didn't expect it! You might have expected an instance of Array. The error occurred while evaluating nil.include?
/Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/ attribute_methods.rb:142:in `create_time_zone_conversion_attribute?' /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/ attribute_methods.rb:75:in `define_attribute_methods' /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/ attribute_methods.rb:71:in `each' /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/ attribute_methods.rb:71:in `define_attribute_methods' /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/ attribute_methods.rb:350:in `respond_to?' /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/ associations/association_proxy.rb:209:in `method_missing' app/views/membre/adhesion.erb:9
Any idea welcome!
Read you, Jej