Shalafister
Shalafister

Reputation: 399

Curl data and combine it with Rails Database

Maybe it sounds stupid but I am a newbie on RoR and really eager to learn.

There are 3 dropdown lists on a web page where I can get data by using terminal curl ... --data e.g: Car brand, year and model, and then I would like to create a database by using RoR with the datas from terminal.

I do not know if thats possible. As an example,

Shown how it looks like

But Imagine I have 100 sections so I would like to create a database with the data I can get from terminal.

Thank you

Upvotes: 0

Views: 55

Answers (2)

max
max

Reputation: 102134

Ruby has several libraries to get data over the net such as Net::HTTP (included in ruby), Typheos and Faraday.

Getting data can be as simple as:

require 'net/http'
uri = URI('http://example.com/index.html?count=10')
Net::HTTP.get(uri) # => String

But at your skill level you should perhaps consider taking a few and Ruby and Rails tutorials before you tackle this project.

Upvotes: 2

Max Williams
Max Williams

Reputation: 32943

You can access the command line in Ruby (and therefore Rails) using backticks (`), or the commands system or shell, or in various other ways.

So, you could do

response = `curl #{url}` 

inside your rails code (model or controller), and parse the results. However, there are a variety of gems already available for pulling html from somewhere (a text file or a webpage via url for example), and extracting content out of it, which are more reliable and easier to use than curl. This process is called "scraping", so a google for "scrape website rails" will get you started.

Nokogiri is a popular choice - eg http://ruby.bastardsbook.com/chapters/html-parsing/

Upvotes: 2

Related Questions