Ruby on Rails Thursday, September 14, 2017

Since I don't have too information about your scripts, I'll just guess some things.

If the scripts are proved to work well (especially if you have unit tests for them), I would recommend to keep them as they are or move them to a gem and use them inside your rails app.

A very simple, proof of concept example:

          # Your already existing class
class ScrapeWebsite
  def initialize(url)
    @url = url
  end

  def call
    # Logic for parsing the page
    # returns a string with the content
  end
end

# Controller
class EventsController
  def index
    @events = Event.all
  end

  def create
    data = ScrapeWebsite.new(params[:url]).call
    Event.create(content: data)

    flash[:success] = 'Data retrieved.'
    redirect_to :back
  end
end

# ActiveRecord model
class Event < ActiveRecord::Base
  validates :content, presence: true
end

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL37D8EJPprgSA8HFHVnLdUpvT_VVBxQpgEtacDuSMPkeeGjZw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment