Forum: Ruby on Rails can't convert Fixnum into String ??

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.
B5a793b425c4db1f45c3cdfec5697047?d=identicon&s=25 scott (Guest)
on 2006-06-01 11:37
I have been getting this error message on various pages, just wondering
if anyone could explain whats going wrong, and the best way to correct
it

code that is cuasing the problem is below
@project = Project.find(:first, :conditions => "id = " +
@purchaseorder.project_id)
Ed5307c79ba5b415b1ddfee48319099b?d=identicon&s=25 Ioana Kanda (Guest)
on 2006-06-01 12:18
(Received via mailing list)
Hi
Maybe this: @purchaseorder.project_id.to_s
Ed5307c79ba5b415b1ddfee48319099b?d=identicon&s=25 Ioana Kanda (Guest)
on 2006-06-01 12:22
(Received via mailing list)
Or: @project = Project.find(:first, :conditions => "id = #{@
purchaseorder.project_id}")
B780ee0ee1480454a85df58536702f63?d=identicon&s=25 Alder Green (Guest)
on 2006-06-01 12:25
(Received via mailing list)
On 6/1/06, scott <scott@boxuk.com> wrote:
> I have been getting this error message on various pages, just wondering
> if anyone could explain whats going wrong, and the best way to correct
> it
>
> code that is cuasing the problem is below
> @project = Project.find(:first, :conditions => "id = " +
> @purchaseorder.project_id)
>

The problem is your attempt to add a number to a string. When adding
foo + bar, if foo is a string, bar should be a string too. The
simplest solution would be to convert @purchaseorder.project_id to a
string with @purchaseorder.project_id.to_s.

A better solution imho would be to embed @purchaseorder.project_id in
a string, like this:

... :conditions => "id = #@purchaseorder.project_id"
B5a793b425c4db1f45c3cdfec5697047?d=identicon&s=25 scott (Guest)
on 2006-06-01 16:19
thanks, kind of makes sense now!
This topic is locked and can not be replied to.