如何在rails应用程序中显示JSON提要的结果?

时间:2013-10-22 01:43:29

标签: ruby-on-rails ruby twitter-bootstrap

我有一个用ruby编写的脚本来解析外部JSON提要中的所有titles。现在我必须将它们显示为data-source,用于twitter bootstrap的typeahead实用程序。

require 'open-uri'
require 'json'

result = JSON.parse(open("http://data.example.com/locations.json").read)

result.each do |bldg|
    puts bldg['title']
end

所以我想在rails app中使用上面的代码片段。

如何在Rails应用程序中应用一些自定义ruby?

谢谢!

2 个答案:

答案 0 :(得分:1)

添加到lib文件夹,然后在需要的地方调用它。

以下是一些很棒的资源:

希望有所帮助。

答案 1 :(得分:0)

作为一个例子

result = `#{Rails.root.join('script/custom.rb')}`