Ruby on Rails Versus Chicago Boss

rrouse edited this page Nov 7, 2011 · 1 revision

Ruby on Rails Versus Chicago Boss

The Chicago Boss API was largely inspired by Rails. The following tables should give you a feel for some of the similarities and differences.

Model

RUBY ON RAILS CHICAGO BOSS
Person.new(:name => "Joe", :age => 4)
person:new(id, "Joe", 4)
@person.save
Person:save()
@person.valid?
Person:validate()
@person.last_name
Person:last_name()
@person.attribute_names
Person:attribute_names()
@person.attributes
Person:attributes()

Associations

RUBY ON RAILS CHICAGO BOSS
belongs_to :manager
-belongs_to(manager).
has_one :partner
-has({partner, 1}).
has_many :pets
-has({pets, many}).
has_many :pets, :foreign_key => "animal_id"
-has({pets, many, [{foreign_key, animal_id}]}).
has_many :pets, :class_name => "Animal"
-has({pets, many, [{module, animal}]}).
has_many :pets, :order => "name ASC"
-has({pets, many, [{sort_by, name}, 
  {sort_order, str_ascending}]}).

Database

RUBY ON RAILS CHICAGO BOSS
Person.find(:all)
boss_db:find(person, [])
Person.find(42)
boss_db:find("person-42")
Person.where("admin = 1")
boss_db:find(person, [admin = 1])
Person.offset(100).limit(10).all
boss_db:find(person, [], 100, 10)

View

RUBY ON RAILS CHICAGO BOSS
<%= @person.name %>
{{ person.name }}
<% if @person %>
  <%= @person.name %>
<% end %>
{% if person %}
  {{ person.name }}
{% endif %}
<% for person in @people %>
-<%= person.name %>
<% end %>
{% for person in people %}
-{{ person.name }}
{% endfor %}
<%= render "shared/header", 
  { :title=> "foo", :user => @person  } %>
{% header title="foo" user=person %}

Controller

RUBY ON RAILS CHICAGO BOSS
def edit
  case request.request_method
  when "GET"
    ...
  when "POST"
    ...
  end
end
edit('GET', []) ->
  ...;
edit('POST', []) ->
  ....
redirect_to :action => 'show', :id => @entry.id
{redirect, "/show/"++Entry:id()}
render :action => "elsewhere"
{render_other, "/elsewhere"}
render :text => "Hello"
{output, "Hello"}
render :json => { :user => @user }
{json, [{user, User}]}
before_filter :require_login, :except => [:show]
before_("show") -> ok;
before_(_) -> require_login().
after_filter :cache, :except => [:login]
after_("login", Res) -> Res;
after_(_, Res) -> cache(Res).
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.