0

In my application I have a field where users can enter a URL and then products will be scraped from that URL. I watched "Screen Scraping with Nokogiri", and I created the result I wanted; I put in a URL and the data gets mined.

  1. How do I implement this into a Rails application?
  2. Do I put my code into a controller?
  3. Does Nokogiri work in controllers?
  4. Do I need to require Nokogiri?
  5. Do I use a Rake task?
  6. If I do use a Rake task, how do I put the user-submitted URL in that Rake task? I read on a previous SO post (not sure where) that executing Rake tasks from the controller is a big security no-no.
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Kwestion
  • 464
  • 5
  • 19

1 Answers1

1
  1. Put into controller? You can put your code into a controller, which means its sync, and user, have to wait until parsing is completed.
  2. Works in controllers? Yes.
  3. Require Nokogiri? Yes.
  4. Rake tasks? Probably no.

You may want to checkout things like Resque.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
fengd
  • 7,551
  • 3
  • 41
  • 44
  • thanks for the heads up on resque. found out that i need to require open-uri in the method i'm using in the controller. Nokogiri does not need a require becuase its in the gemfile but I could require it for kicks. – Kwestion Oct 29 '13 at 04:08