Question

I'm using Ruby on Rails and Jbuilder gem.

I'm trying to get an attribute of a point like this:

{
"point":[33,11]
}

My model are like this

class Point < ActiveRecord::Base
attr_accessible :x, :y
end

I'm trying with this, but was not successfully, it returns the point as a string and I need it as integer.

json.point "[#{point.x},#{point.y}]"

Thanks!!!!

Was it helpful?

Solution

Building on Qumara's comment, you should call point.x.to_i and point.y.to_i.

You should also remove the quotes around your array parameter.

The line in question inside your JBuilder block should look like

json.point [point.x.to_i,point.y.to_i]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top