Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Web applications with Ruby, not Rails

Web applications with Ruby, not Rails

These days, whenever you say that you're building a web application with Ruby, its almost implied that you will be using Rails to do so.

Well, what if you don't want to use Rails? Or Sinatra? Or any other Framework for that matter. What if you just want to roll your own code for routing, controllers, rendering and models?

David Padilla

April 23, 2014
Tweet

More Decks by David Padilla

Other Decks in Technology

Transcript

  1. <% set conn=Server.CreateObject("ADODB.Connection") conn.Open "northwind" %> <html> <head> <title>Super App</title>

    <link href="style.css" /> </head> <body> <h1>Page 1</h1> <% ' Some code here that connects to the DB and ' displays stuff %> </body> </html> page1.asp
  2. <% set conn=Server.CreateObject("ADODB.Connection") conn.Open "northwind" %> <html> <head> <title>Super App</title>

    <link href="style.css" /> </head> <body> <h1>Another Page</h1> <% ' Some code here that connects to the DB and ' displays stuff %> </body> </html> AnotherPage.asp
  3. Index.asp <!--#include file="database.asp"--> <html> <head> <title>Super App</title> <link href="style.css" />

    </head> <body> <% page = Request.QueryString("page") Select Case page Case "page1" %> <!--#include file="page1.asp"--><% Case "AnotherPage" %> <!--#include file="AnotherPage.asp"--><% End Select %> </body> </html>
  4. MVC

  5. model/user.rb require 'sequel' ! DB = Sequel.sqlite ! class User

    ! def self.all DB[:users].to_a end ! end
  6. model/user.rb require 'pg' ! DB = PG.connect( dbname: 'test', host:

    'localhost') ! class User def self.all result = DB.exec "SELECT * FROM users" fields = result.fields result.collect do |row| hash = {} row.each_with_index do |value, i| hash[fields[i]] = value end end end end