Querying records. HELP!

V

Vincent Hernandez

I'm new to this language so i don't know much of it. I'm trying to query
records to show it in the list view in the web. This is the line of sql
that I'm trying to produce: SELECT source FROM table WHERE source LIKE
'%CMS%'. Can someone help me on this? And can you show displaying the
records that i've gathered step by step?
 
B

Brian Candler

Vincent said:
I'm new to this language so i don't know much of it. I'm trying to query
records to show it in the list view in the web. This is the line of sql
that I'm trying to produce: SELECT source FROM table WHERE source LIKE
'%CMS%'. Can someone help me on this?

You need a database-access library. Choices include:

* Use the native adapters for mysql, sqlite3 or whatever directly. e.g.
http://www.kitebird.com/articles/ruby-mysql.html

However if you want to change which DB you are using, you'll need to
change your code.

* Use ruby-dbi, which lets you use the same API to connect to any of
these databases, making it easier to port your code between databases.
http://www.kitebird.com/articles/ruby-dbi.html

* Use a higher-level API like ActiveRecord, DataMapper or Sequel, which
will construct queries for you and/or give you an object representation
of your result rows.
http://ar.rubyonrails.org/
And can you show displaying the
records that i've gathered step by step?

In the old days you might have written a CGI or FastCGI program to do
this. In the new world you'll probably want a web framework like Sinatra
(small and simple) or Rails (large and featureful)

A simple Sinatra program looks like this:

require 'sinatra'
get '/' do
"hello world" # <= replace with code to query your DB
# and generate a HTML page with table
end

You probably also want to look at a templating library to help you
insert dynamic content into your HTML pages, like ERB (similar to PHP,
insert Ruby directly into your HTML) or HAML. Sinatra and Rails both
have helper methods to let you use these templating systems, and others
are available as plugins.

If you don't really know where to start, Rails is probably the best, due
to the huge amount of documentation available. Some good starting points
are
http://guides.rubyonrails.org/
http://railscasts.com/

The tutorial which got me hooked was
http://oreilly.com/ruby/archive/rails-revisited.html
although it's pretty old now (for Rails 1.2.x, whereas Rails 2.3.x is
now current and 3.x is about to be released)

Note that Rails is a huge piece of code in its own right, and questions
about Rails are best asked on a Rails mailing list. The Ruby mailing
list is more for general questions about the Ruby programming language.

HTH,

Brian.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top