Ruby On Rails - Framework Comparison

WebappFrameworkComparison / Scratchbook / RubyOnRails

Ruby on Rails ..

Here is my log: http://herbert.poul.at/board/thread/579/?page=1

It took me a total of 4 hours (and 2 minutes) - I'm not really satisfied with the results, but it does the job. the most useful resources were a developer.apple.com site: http://developer.apple.com/tools/rubyonrails.html and the really painful-to-use api http://api.rubyonrails.org/

1. Screenshots

  • edit/create bar
  • list bars
  • show bar

2. Evaluation

In WebappFrameworkComparison/Planning i prepared a few questions, so i now try to answer them ...

How easy was the framework to learn ?

well.. i had no previous knowledge of ruby .. and still found my way around the code.. and could start customizing the scaffolding template .. (probably because there is already so much code that it's no problem to tweak it)

How easy was the setup ?

easy enough .. downloaded "Locomotive" http://locomotive.raaum.org/ and everything worked fine - But it shouldn't be any harder for a server environment i guess.. there are just 3 components .. ruby, rails and mysql .. so it can't be that hard ..

How easy is the deployment of new versions ?

Should be easy .. update the files, run the migration files (for database schema updates) and everything should work already ... (migration files aren't really powerful .. but with a bit of luck .. they might even work sometimes)

How extend able is the result ? (e.g. Imagine i would like to add a workflow where changes get online once an administrator approves them)

Well.. i doubt the extensibility a bit.. but if you remove all the autogenerated code and do it by hand.. there shouldn't be any problem left ..

How much duplication was necessary ? (e.g. need to describe the models in the database as well as in code or xml ? / need to describe attributes of models in models and views ?, etc.)

well.. for "normal" types it's not all that bad.. e.g. if you add a new string .. simply add the migration file .. and modify the _form.html (no idea if this is supposed to happen automatically ?) .. and this should be .. it.. but once you add a relation or even a many-to-many relation ship this is not that easy anymore.. you have to code it .. in 1. _form.html, 2. the controller for create AND update 3. list.html 4. show.html .. and add it in 5. migration file, 6. BOTH models if it is a 1:n relation (belongs_to and has_many on the other side)

i don't think this is all that great...

How much useless code (code which is the same for every application, view, model, ...) was required

how about a little quote from a tutorial on onlamp.com:

[...] so I'll open cookbook2\app\controllers\recipe_controller.rb (Figure 17)
and add a line to both the create and update methods.

or the tutorial on many-to-many relationships:

Add the @tags=Tag.find_all line to both the new and edit methods as depicted in line 17 & 32 below.

other than that .. most useless code was auto generated.. isn't that great ?

URLs:

How does the mapping of URLs work ?

there is a routes.rb which has a simple default route which should work for most applications:

map.connect ':controller/:action/:id.:format'
map.connect ':controller/:action/:id'

e.g. /bars/list or /bars/show/1

How can you link within templates to other actions/views/... ?

there is a link_to template function which gets passed a controller, action and optionally id. (ie. the params which are defined in the route)

3. Various Comments

3.1. DRY

Don't Repeat Yourself !!! and i also apply this to frameworks - they shouldn't repeat themselves ! just because stuff is generated by scripts, doesn't mean it is not there.. if it is the same for all applications, why not just put it into a generic base class, instead of copying it to every controller/template/.. ?

And why does every documentation say 'create this line in both create and update' - this has to stop ! i want to accomplish one single task, why do i have to add the same line of code to two different methods ?

4. Code Examples

4.1. Migration file

class Bar < ActiveRecord::Migration
  def self.up
    create_table :bars do |table|
      table.column :name,         :string
      table.column :location,     :text
      table.column :wifi,         :integer # 1 - Yes, 2 - No, 3 - Paid
      table.column :creationdate, :timestamp
      table.column :editdate,     :timestamp
    end
  end

  def self.down
    drop_table :bars
  end
end

4.2. Model

class Bar < ActiveRecord::Base
  has_and_belongs_to_many :beers
  belongs_to :user

  has_many :comments

  validates_presence_of :name

  def wifi_descr
    return "Yes" if wifi == 1
    return "No" if wifi == 2
    return "Paid" if wifi == 3
  end

end

4.3. Controller

i show new/create here.. but edit/update looks EXACTLY the same ...

  def new
    @bar = Bar.new
    @beers = Beer.find_all
  end

  def create
    @bar = Bar.new(params[:bar])
    @bar.editdate = Time.now
    @bar.beers = Beer.find(params[:beer_ids]) if params[:beer_ids]
    @bar.user_id = current_user.id
    if @bar.save
      flash[:notice] = 'Bar was successfully created.'
      redirect_to :action => 'list'
    else
      render :action => 'new'
    end
  end

4.4. Template (View)

this is the _forms.rhtml template which is used to edit and create bars. it was 70% autogenerated

<%= error_messages_for 'bar' %>

<!--[form:bar]-->
<p><label for="bar_name">Name</label><br/>
<%= text_field 'bar', 'name'  %></p>

<p><label for="bar_location">Location</label><br/>
<%= text_area 'bar', 'location'  %></p>

<p><label for="bar_beers">Beers</label><br/>
<%= select 'bar', 'beer_ids', Beers.find_all.collect { |b| [ b.name, b.id ] }, { }, { :multiple => 'multiple' } %>

<p><label for="bar_wifi">Wifi</label><br/>
<%= select 'bar', 'wifi', { 'Yes' => 1, 'No' => 2, 'Paid' => 3 } %></p>
<!--[eoform:bar]-->

5. Conclusion

Ruby On Rails definitively has a few good ideas and seems to have restarted the hype about KISS web frameworks (if i can call it that?) - which i think is a very good thing. But Ruby On Rails is by far not perfect and therefore quite over hyped in my opinion - maybe i had too high expectations or didn't look deep enough .. but the tutorials didn't lead to anything better.

So i'm a bit disappointed. But it is still a quite good web framework.

Last Modified: 2007-11-18 17:47:51 by Herbert Poul - [ Snip Changes ] [ Wiki History ]

0 Comments

No comments yet.

Please login to create a new thread.

Personal website and blog of Herbert Poul. Also check out my Photo Gallery.




Herby's Photo Gallery

Subscriptions

User

You are not logged in.
Login
Register