Can't convert Fixnum into String?


#1

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)


#2

Hi
Maybe this: @purchaseorder.project_id.to_s


#3

Or: @project = Project.find(:first, :conditions => “id = #{@
purchaseorder.project_id}”)


#4

On 6/1/06, scott removed_email_address@domain.invalid 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


#5

thanks, kind of makes sense now!