Import a URL With Ruby

Billy Heaton 1 min read

def importHTML
require 'open-uri'
@source = open("http://domain.com/some.html").read
end

# uses a reference parameter when getting remote XML
def importXML
  require 'open-uri'
  @aclass = AClass.find(params[:id]) # expecting a param named ref
  @content = open("http://domain.com" + @aclass.ref + "&type=xml").read
  respond_to do |format|
    format.xml  { render :xml => @content }
  end
end

About the Author

Billy Heaton
Billy Heaton

Software engineer with two decades of experience who favors Ruby and JavaScript to build web applications