开发者

Escape methods within single qoutes

开发者 https://www.devze.com 2023-04-13 03:32 出处:网络
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

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

精彩评论

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