# Strange error

**URL:** <https://www.ruby-forum.com/t/strange-error/157034>\
**Category:** Rails\
**Created:** [January 6, 2009, 5:39pm UTC](https://www.ruby-forum.com/t/strange-error/157034 "2009-01-06T17:39:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jej](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b782af/32.png) [@Jej](https://www.ruby-forum.com/u/Jej)\
**Post date:** [January 6, 2009, 5:39pm UTC](https://www.ruby-forum.com/t/strange-error/157034/1 "2009-01-06T17:39:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Jej](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b782af/32.png) [@Jej](https://www.ruby-forum.com/u/Jej)\
**Post date:** [January 6, 2009, 5:55pm UTC](https://www.ruby-forum.com/t/strange-error/157034/2 "2009-01-06T17:55:14Z")

</div>

Well, sorry to make noise! The solution is here:  
[http://www.railsformers.com/article/activerecord-timezone-settings-bug](http://www.railsformers.com/article/activerecord-timezone-settings-bug)

It seems to be a bug. I just added

config.active\_record.default\_timezone = :utc

in my env.rb…

Jej
