开发者

Escape methods within single qoutes

I am using the gmaps4rails gem and building my own markers json in my controller, but because it is in single qoutes it does not recognize my variables (@claim.longitude). Is it possible to escape the single qoutes, or is there another way to do this开发者_JAVA百科?

@markers = '[{"description": "", "title": "My Location: Seattle", "sidebar": "",
         "lng": "#{@claim.longitude}", "lat": "#{@claim.latitude}", 
         "picture": "", "width": "", "height": ""}]'


Let Rails create the JSON for you.

> json_string = [{"foo" => "bar", "fred" => "barney"}].to_json
> puts json_string
[{"fred":"barney","foo":"bar"}]

If you get to the point where you want to convert your models into JSON, then look up the as_json method as well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜