Insert the code into a library of your rails app as a method. Usually the library is placed in lib/ folder from root of Rails app. Then call the defined method directly from a controller, the call :respond
method to handle the request from a browser, and output result of the method work in a view. If the grab procedure take a lot of tike use asyncronous operations, for example with event-machine gem.
The simplest app is the following:
app/controllers/your_controller.rb
def index
result = WebGrab.grab "http://hackerstreet.in"
render text: result.inspect # just renders text, replace it as a call to render a view
end
lib/webgrab.rb
require 'nokogiri'
require 'open-uri'
module WebGrab
def self.grab uri
page = Nokogiri::HTML( open uri )
links = page.css("a")
[ links.length, puts links[0].text, links[0]["href"] ]
end
end