Friday, 9 August 2013

How to integrate rake task with view file in Rails App

How to integrate rake task with view file in Rails App

I'm trying to create a parser based on Rails App and I use for this
'nokogiri'. I watched railscast by Ryan Bates about this but I don't
understand how he integrated task with view.
For example: In my view file I press the button - task starts to collect
information and shows this information on the same page. How can I do
this?
My example task:
desc "example"
task :parsing => :environment do
require 'rubygems'
require 'nokogiri'
require 'open-uri'
page = Nokogiri::HTML(open('http://en.wikipedia.org/wiki/HTML'))
page.css('div#content div#bodyContent table.infobox tr th').each do |el|
puts el.text
end
end
Or maybe I shouldn't use for parser rake task? Maybe I should put my
parser in controller or in model or in helper?

No comments:

Post a Comment