25
 Rails vs Web2Py From ”Ruby On Rails” to ”Web to Python” http://jon.is.emotionull.com

Rails vs Web2py

Embed Size (px)

DESCRIPTION

My presentation for Athens Digital Week 2009

Citation preview

Page 1: Rails vs Web2py

   

Rails vs Web2Py

From ”Ruby On Rails” to ”Web to Python”

http://jon.is.emotionull.com

Page 2: Rails vs Web2py

   

Controllers

  class MyTestController < ApplicationController    def index        render_text “Hello World”    endend

 

def index():     return "Hello World"

Page 3: Rails vs Web2py

   

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

   

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

   

Routing

routes.rb

 

routes.py (reversed routing, with or without regex, IP filtering)

Page 6: Rails vs Web2py

   

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

   

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

   

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

   

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

   

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

   

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

   

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

   

Gems / Plugins

Lots of them 

Free Appliaces (plugin system still under planning)

Page 14: Rails vs Web2py

   

Installation

Must install ruby, Rails, gems, databases 

Just a zip (cross­platform)

Page 15: Rails vs Web2py

   

Web Administration

Nope

 

Killer­full fledged administration (even dedicated for apps)

Page 16: Rails vs Web2py

   

Upload files

Plugins (paperclip)

Built in (specify as an 'upload' field

Page 17: Rails vs Web2py

   

Users/Roles

Plugins

 

Built in (trivial to override)

Page 18: Rails vs Web2py

   

Application Distribution 

'Frozen' Applications 

 

Share the application directory

ByteCode compilation

Page 19: Rails vs Web2py

   

Ticketing system/VC/ Unit testing

External

 

Built­in (you can even make patches via web interface)

Page 20: Rails vs Web2py

   

Google App Engine

via JRuby (with LOTS of changes and hacks)

 

Natively (only framework that runs UNMODIFIED on GAE)

Page 21: Rails vs Web2py

   

Caching

MemCache

For any function cache: in RAM, disk, memcache or combinations

Page 22: Rails vs Web2py

   

Translations

Natively (but still hard to use)

You can add/edit translations via web interface

Page 23: Rails vs Web2py

   

Routing

routes.rb

routes.py (reversed routing, with or without regex, IP filtering)

Page 24: Rails vs Web2py

   

Support

Many books, very big community and tutorials

 

Two 'manual' books, smaller but dedicated community

Page 25: Rails vs Web2py

   

 

Thank for watching! Questions?

http://[email protected]