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?

0f9c9bbecc4067b9bce445cb11ed5d53?s=128

David Padilla

April 23, 2014
Tweet

Transcript

  1. David Padilla @dabit

  2. None
  3. www.magmaconf.com

  4. Web applications with Ruby (not Rails)

  5. I invented MVC on ASP Classic

  6. None
  7. Not really

  8. <% 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
  9. <% 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
  10. 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>
  11. 2000

  12. None
  13. MVC

  14. None
  15. http://therantygirl.files.wordpress.com/2012/07/happy-cat.jpg

  16. Mid Programmer Life Crisis

  17. Programming Web applications with Rails is BORING

  18. Building websites with Rails is not ENOUGH programming

  19. None
  20. None
  21. None
  22. None
  23. Most of us don’t know what’s going on outside of

    Rails
  24. We used to have all these problems

  25. We used to actually write SQL

  26. Bring programming back

  27. Web applications with Ruby (not Rails)

  28. Rack

  29. Rack is cool as Bow Ties

  30. Web Server Web Application A hash with request headers

  31. Web Server Web Application A hash with request headers respond_to(:call)

  32. Web Server Web Application A hash with request headers

  33. [http_code, headers, body]! Integer Hash Responds to :each

  34. Web Server Web Application [http_code, headers, body]!

  35. run -> (env) { puts env [200, {}, []] }

    config.ru
  36. Live Code

  37. Router

  38. /posts PostController #index

  39. None
  40. None
  41. Models

  42. ActiveRecord::Base

  43. require 'active_record' ! class User < ActiveRecord::Base #... end model/user.rb

  44. Sequel

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

    ! def self.all DB[:users].to_a end ! end
  46. pg ! mysql

  47. 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
  48. One last piece of advice

  49. Don’t actually do this

  50. None
  51. None
  52. Logging Caching Database Pooling Sessions Cookies Security

  53. Read code

  54. Try to understand how things work

  55. Write your own framework!

  56. <3  Rails Core Team

  57. Disclaimer: I do NOT actually think that writing web applications

    with Rails is BORING
  58. github.com/dabit/wawr

  59. @dabit david@crowdint.com Thank You!