Use a reader
Subscribe by Email
Blog » Hobo Organizations - Your first hobo rails application
Posted on 22 Nov 2010 10:27
Quick steps to make a hobo application. Let's have a database of organizations with a name.
Important Note! Hobo for Rails 3 is still Beta. Therefore in production, I am still using Rails 2…. When Hobo for Rails 3 is out of Beta it will be a heaven. Counting down. Soon… Thus this article and related pages are written on Rails 2.
Goto your console and:
hobo organizations cd organizations script/generate hobo_model_resource Organization name:string
Now edit app/models/organization.rb and enhance the name field definition:
fields do name :string, :required, :unique, :null=>false, :index=>true timestamps end
And continue on the console:
script/generate hobo_migration rake db:migrate script/server
Try your application at http://localhost:3000
If you don't have Rails and/or Hobo then….
Do Ruby on the Rails Installation. Then install hobo:
sudo gems install hobo
Hobo Fields API
name :string, :required, :unique
:required and :unique are parameters of Hobo Fields API. They add validations to the field. Note that they only add validations. They do not modify the database.
name :string, :required, :unique, :null=>false, :index=>true
:null=>false and :index=>true are process by Hobo Migration Generator. They modify the database schema! Now :name field has a unique index as well and it cannot be :null.
Migration parameters must follow field API parameters! The code below will not work!
name :string, :required, :null=>false, :unique , :index=>true #Wrong hobo code
Multi field indexes
An example of declaring indexes over multiple fields:
fields do ... end index [:first_name, :last_name], :unique=>true
In addition to the ability to specify an index per field, you can add indexes over multiple fields to ensure uniqueness.
- Ruby on the Rails Installation
- Rails Guides
You can continue at Full Stack Testing a Hobo Application
If you like this page, please spread the word:
You can contact me if you have questions or corrections.