From: Vincent Hernandez on 13 Apr 2010 06:41 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/.
From: Brian Candler on 13 Apr 2010 06:56 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/.
|
Pages: 1 Prev: Help required with dm-geokit Next: IronRuby 1.0 has been released |