Forum: Ruby undefined method `convert_to' for false:FalseClass

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
E5b95d356f10195ce66306461345b137?d=identicon&s=25 Dean (Guest)
on 2006-03-06 04:19
I have a rails app (so maybe this is a question for the rails list) that
uses a temperature class I also wrote.  When the app goes to save a new
record, I get this error message.

undefined method `convert_to' for false:FalseClass

Why is convert_to being passed a flase object? The method is:

def ==(t_obj)
  @temp == t_obj.convert_to(@units).temp
end

the convert_to method converts a temperature object to the requested
units (C, F, K).
It is coming from:

#{RAILS_ROOT}/app/models/temperature.rb:82:in `=='
#{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/callbacks.rb:248:in
`create_or_update'
<snip>

Regards,
--Dean
D111305c32e46f7dd2794a956208d347?d=identicon&s=25 E. Saynatkari (Guest)
on 2006-03-06 06:21
Dean wrote:
> I have a rails app (so maybe this is a question for the rails list) that
> uses a temperature class I also wrote.  When the app goes to save a new
> record, I get this error message.
>
> undefined method `convert_to' for false:FalseClass
>
> Why is convert_to being passed a flase object? The method is:

It could just be Rails weirdness. Paste the code where the call
is, if at all possible. In the meanwhile, try this workaround to
see if this is a problem or just something Rails did not expect
you to do:

> def ==(t_obj)
>   @temp == t_obj.convert_to(@units).temp
> end

  def ==(other)
    other and @temp == other.convert_to(@units).temp
  end

Here we fail immediately if other is nil or false.

> the convert_to method converts a temperature object to the requested
> units (C, F, K).
> It is coming from:
>
> #{RAILS_ROOT}/app/models/temperature.rb:82:in `=='
> #{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/callbacks.rb:248:in
> `create_or_update'
> <snip>
>
> Regards,
> --Dean


E
This topic is locked and can not be replied to.