Querying records. HELP!

Discussion in 'Ruby' started by Vincent Hernandez, Apr 13, 2010.

  1. 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?
    --
    Posted via http://www.ruby-forum.com/.
     
    Vincent Hernandez, Apr 13, 2010
    #1
    1. Advertising

  2. Vincent Hernandez wrote:
    > 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.
    --
    Posted via http://www.ruby-forum.com/.
     
    Brian Candler, Apr 13, 2010
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark
    Replies:
    0
    Views:
    327
  2. Marlon
    Replies:
    0
    Views:
    464
    Marlon
    Jul 22, 2004
  3. Luke Airig
    Replies:
    0
    Views:
    816
    Luke Airig
    Dec 31, 2003
  4. Dan

    Delete records or update records

    Dan, May 10, 2004, in forum: ASP General
    Replies:
    1
    Views:
    480
    Ray at
    May 10, 2004
  5. Replies:
    3
    Views:
    692
    Anthony Jones
    Nov 2, 2006
Loading...

Share This Page