0

I have a script that I have written in ruby to parse all the titles in external JSON feed. Now I have to show them as data-source for the typeahead utility of twitter bootstrap.

require 'open-uri'
require 'json'

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

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

So I want to use the above snippet in the rails app.

How to apply some custom ruby inside a Rails app?

Thanks!

Community
  • 1
  • 1
Clone
  • 919
  • 4
  • 11
  • 22

2 Answers2

1

Add to the lib folder and then call it where needed.

Here are some great resources:

Hope that helps.

Community
  • 1
  • 1
RyanJM
  • 7,028
  • 8
  • 60
  • 90
0

As an example

result = `#{Rails.root.join('script/custom.rb')}`
Danil Speransky
  • 29,891
  • 5
  • 68
  • 79