开发者

rails 3 json encode for consumption in javascript

I know that to_json is deprecated and as_json is giv开发者_如何学运维ing me problems.

This line works fine, but to_json is deprecated:

new IS.Presentation(<%= raw(@course_step.step.step_presentation.step_presentation_files.map { |item| {'url' => item.slide.url, 'title' => item.title}}.to_json) %>)

Any ideas?


ActiveSupport supports JSON. You can see here:

ruby-1.9.2-p136 :003 > j = ActiveSupport::JSON
 => ActiveSupport::JSON 
ruby-1.9.2-p136 :004 > j.encode({:team => "Celtics", :players => "20"})
 => "{\"team\":\"Celtics\",\"players\":\"20\"}" 
ruby-1.9.2-p136 :005 > j.decode("{\"team\":\"Celtics\",\"players\":\"20\"}")
 => {"team"=>"Celtics", "players"=>"20"}

So for you it would be:

new IS.Presentation(<%= ActiveSupport::JSON.encode(raw(@course_step.step.step_presentation.step_presentation_files.map { |item| {'url' => item.slide.url, 'title' => item.title}})) %>)
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜