Question

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.
Was it helpful?

Solution

  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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top