rails vs web2py
DESCRIPTION
My presentation for Athens Digital Week 2009TRANSCRIPT
![Page 1: Rails vs Web2py](https://reader034.vdocuments.mx/reader034/viewer/2022051412/54bd19824a7959766e8b45cb/html5/thumbnails/1.jpg)
Rails vs Web2Py
From ”Ruby On Rails” to ”Web to Python”
http://jon.is.emotionull.com
![Page 2: Rails vs Web2py](https://reader034.vdocuments.mx/reader034/viewer/2022051412/54bd19824a7959766e8b45cb/html5/thumbnails/2.jpg)
Controllers
class MyTestController < ApplicationController def index render_text “Hello World” endend
def index(): return "Hello World"
![Page 3: Rails vs Web2py](https://reader034.vdocuments.mx/reader034/viewer/2022051412/54bd19824a7959766e8b45cb/html5/thumbnails/3.jpg)
Params
class MyTestController < ApplicationController def index render_text “Hello ”+params[:who] endend
def index(): return "Hello %s" % request.vars.who
def index(): return "Hello %s" % request.args[0]
![Page 4: Rails vs Web2py](https://reader034.vdocuments.mx/reader034/viewer/2022051412/54bd19824a7959766e8b45cb/html5/thumbnails/4.jpg)
Dispatching
class MyTestController < ApplicationController def index render_text “Hello World” endend
def index(): return "Hello %s" % request.vars.who
http://hostname/myapp/mycontroller/index calls
http://hostname/MyTest/index
![Page 5: Rails vs Web2py](https://reader034.vdocuments.mx/reader034/viewer/2022051412/54bd19824a7959766e8b45cb/html5/thumbnails/5.jpg)
Routing
routes.rb
routes.py (reversed routing, with or without regex, IP filtering)
![Page 6: Rails vs Web2py](https://reader034.vdocuments.mx/reader034/viewer/2022051412/54bd19824a7959766e8b45cb/html5/thumbnails/6.jpg)
Views
<table> <% @recipes.each do |recipe| %> <tr> <td><%= recipe.name %></td> </tr> <% end %></table>
<table> {{for recipe in recipes:}}> <tr> <td>{{=recipe.name}}</td> </tr> {{pass}}</table>
![Page 7: Rails vs Web2py](https://reader034.vdocuments.mx/reader034/viewer/2022051412/54bd19824a7959766e8b45cb/html5/thumbnails/7.jpg)
Passing vars in views
class MyTestController < ApplicationController def index @message=“Hello World” endend
def index(): return dict(message=”Hello World”)
![Page 8: Rails vs Web2py](https://reader034.vdocuments.mx/reader034/viewer/2022051412/54bd19824a7959766e8b45cb/html5/thumbnails/8.jpg)
Layouts
<title>Layout Example</title> <body> <%= yield %> </body></html>
<title>Layout Example</title> <body> {{include}} </body></html>
and in view:{{extend ‘layout.html’}}body
![Page 9: Rails vs Web2py](https://reader034.vdocuments.mx/reader034/viewer/2022051412/54bd19824a7959766e8b45cb/html5/thumbnails/9.jpg)
Forms
<%= form_tag :action => "update" dp %> Name: <%= text_field "item", "name" %><br /> Value: <%= text_field "item", "value" %><br /> <%= submit_tag %><%= end %>
def contact(): form = SQLFORM(Article) if form.accepts(request.vars): redirect('thanks') return dict(form=form)
![Page 10: Rails vs Web2py](https://reader034.vdocuments.mx/reader034/viewer/2022051412/54bd19824a7959766e8b45cb/html5/thumbnails/10.jpg)
Validation
ActiveForm::Definition::create :article do |f| f.section :details do |s| s.text_element :email,:class => 'required' do |e| e.validates_as_email :msg => 'not email' endend
db.define_table(‘Article’,SQLField(‘email’))db.Article.email.requires=IS_EMAIL()
![Page 11: Rails vs Web2py](https://reader034.vdocuments.mx/reader034/viewer/2022051412/54bd19824a7959766e8b45cb/html5/thumbnails/11.jpg)
Migrations
class Article < ActiveRecord::Migration def self.up create_table :articles do |t| t.column :name, :string t.column :description, :text end endend
Article=db.define_table(‘Article’, SQLField(‘email’,’string’), SQLField(‘description’,’text’)
![Page 12: Rails vs Web2py](https://reader034.vdocuments.mx/reader034/viewer/2022051412/54bd19824a7959766e8b45cb/html5/thumbnails/12.jpg)
Queries
Article.find(:first,:conditions => [ "id > :id AND name = :name", {:id => 3, :name => "test" }])
db(Article.id>3 and Article.name==’test’).select()
![Page 13: Rails vs Web2py](https://reader034.vdocuments.mx/reader034/viewer/2022051412/54bd19824a7959766e8b45cb/html5/thumbnails/13.jpg)
Gems / Plugins
Lots of them
Free Appliaces (plugin system still under planning)
![Page 14: Rails vs Web2py](https://reader034.vdocuments.mx/reader034/viewer/2022051412/54bd19824a7959766e8b45cb/html5/thumbnails/14.jpg)
Installation
Must install ruby, Rails, gems, databases
Just a zip (crossplatform)
![Page 15: Rails vs Web2py](https://reader034.vdocuments.mx/reader034/viewer/2022051412/54bd19824a7959766e8b45cb/html5/thumbnails/15.jpg)
Web Administration
Nope
Killerfull fledged administration (even dedicated for apps)
![Page 16: Rails vs Web2py](https://reader034.vdocuments.mx/reader034/viewer/2022051412/54bd19824a7959766e8b45cb/html5/thumbnails/16.jpg)
Upload files
Plugins (paperclip)
Built in (specify as an 'upload' field
![Page 17: Rails vs Web2py](https://reader034.vdocuments.mx/reader034/viewer/2022051412/54bd19824a7959766e8b45cb/html5/thumbnails/17.jpg)
Users/Roles
Plugins
Built in (trivial to override)
![Page 18: Rails vs Web2py](https://reader034.vdocuments.mx/reader034/viewer/2022051412/54bd19824a7959766e8b45cb/html5/thumbnails/18.jpg)
Application Distribution
'Frozen' Applications
Share the application directory
ByteCode compilation
![Page 19: Rails vs Web2py](https://reader034.vdocuments.mx/reader034/viewer/2022051412/54bd19824a7959766e8b45cb/html5/thumbnails/19.jpg)
Ticketing system/VC/ Unit testing
External
Builtin (you can even make patches via web interface)
![Page 20: Rails vs Web2py](https://reader034.vdocuments.mx/reader034/viewer/2022051412/54bd19824a7959766e8b45cb/html5/thumbnails/20.jpg)
Google App Engine
via JRuby (with LOTS of changes and hacks)
Natively (only framework that runs UNMODIFIED on GAE)
![Page 21: Rails vs Web2py](https://reader034.vdocuments.mx/reader034/viewer/2022051412/54bd19824a7959766e8b45cb/html5/thumbnails/21.jpg)
Caching
MemCache
For any function cache: in RAM, disk, memcache or combinations
![Page 22: Rails vs Web2py](https://reader034.vdocuments.mx/reader034/viewer/2022051412/54bd19824a7959766e8b45cb/html5/thumbnails/22.jpg)
Translations
Natively (but still hard to use)
You can add/edit translations via web interface
![Page 23: Rails vs Web2py](https://reader034.vdocuments.mx/reader034/viewer/2022051412/54bd19824a7959766e8b45cb/html5/thumbnails/23.jpg)
Routing
routes.rb
routes.py (reversed routing, with or without regex, IP filtering)
![Page 24: Rails vs Web2py](https://reader034.vdocuments.mx/reader034/viewer/2022051412/54bd19824a7959766e8b45cb/html5/thumbnails/24.jpg)
Support
Many books, very big community and tutorials
Two 'manual' books, smaller but dedicated community