Rails vs Web2py
-
Upload
jonromero -
Category
Technology
-
view
6.918 -
download
5
description
Transcript of Rails vs Web2py
Rails vs Web2Py
From ”Ruby On Rails” to ”Web to Python”
http://jon.is.emotionull.com
Controllers
class MyTestController < ApplicationController def index render_text “Hello World” endend
def index(): return "Hello World"
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]
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
Routing
routes.rb
routes.py (reversed routing, with or without regex, IP filtering)
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>
Passing vars in views
class MyTestController < ApplicationController def index @message=“Hello World” endend
def index(): return dict(message=”Hello World”)
Layouts
<title>Layout Example</title> <body> <%= yield %> </body></html>
<title>Layout Example</title> <body> {{include}} </body></html>
and in view:{{extend ‘layout.html’}}body
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)
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()
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’)
Queries
Article.find(:first,:conditions => [ "id > :id AND name = :name", {:id => 3, :name => "test" }])
db(Article.id>3 and Article.name==’test’).select()
Gems / Plugins
Lots of them
Free Appliaces (plugin system still under planning)
Installation
Must install ruby, Rails, gems, databases
Just a zip (crossplatform)
Web Administration
Nope
Killerfull fledged administration (even dedicated for apps)
Upload files
Plugins (paperclip)
Built in (specify as an 'upload' field
Users/Roles
Plugins
Built in (trivial to override)
Application Distribution
'Frozen' Applications
Share the application directory
ByteCode compilation
Ticketing system/VC/ Unit testing
External
Builtin (you can even make patches via web interface)
Google App Engine
via JRuby (with LOTS of changes and hacks)
Natively (only framework that runs UNMODIFIED on GAE)
Caching
MemCache
For any function cache: in RAM, disk, memcache or combinations
Translations
Natively (but still hard to use)
You can add/edit translations via web interface
Routing
routes.rb
routes.py (reversed routing, with or without regex, IP filtering)
Support
Many books, very big community and tutorials
Two 'manual' books, smaller but dedicated community