Life Of Navin

Random Musings, Random Bullshit.


Using Hobo With Rails 3 and MySQL!

For my college project this semester, We (me, Damodar "Damu" Dukle and Poonam "Patlinbai" Patil) chose to use Ruby on Rails, a framework that has been used to create tonnes of stunning webapps. As a developer, Ruby on Rails (or RoR) has been of great interest since the "Convention over Configuration" philosophy RoR emphasizes upon leads to a quick, non-repetitive coding. For the backend, we decided to stick with MySQL, a SQL that all 3 of us are experienced and comfortable with.

Now for our project, we'll be designing a webapp called Press Play, a sort of Napster meets Last.FM meets SoundCloud mega-mashup... more on that some other time (probably once we finish it).

Now, one of the first things we needed to get done was user authentication. And I recalled Kaustubh (@geekblues) telling me about Hobo, a framework that builds upon RoR, and simplifies tasks such as user authentication, permissions and object lifecycles. And after using Hobo, I must say, I am very impressed! :)

The following is a simple tutorial to get up and running with Hobo on Rails 3.x.

1. Setup Ruby and Ruby on Rails. Follow this tutorial if you need to.

2. Next step is ofcourse to install the Hobo gem. Now there's a small issue here. If you use the stadard gem install hobo command, it installs Hobo 1.0.3, which is incompatible with Rails 3.x. Hence we use the command gem install hobo --pre , which installs a prebuild of Hobo 1.3.0, which is compatible with Rails 3.x.

C:\Press_Play>gem install hobo --pre
Fetching: hobo-1.3.0.pre29.gem (100%)
Successfully installed hobo-1.3.0.pre29
1 gem installed
Installing ri documentation for hobo-1.3.0.pre29...
Installing RDoc documentation for hobo-1.3.0.pre29...

3. Start MySQL . Let's use XAMPP here as well (as discussed here). Install the mysql and mysql2 gems using

C:\Press_Play>gem install mysql
Fetching: mysql-2.8.1-x86-mingw32.gem (100%)
Successfully installed mysql-2.8.1-x86-mingw32
1 gem installed
Installing ri documentation for mysql-2.8.1-x86-mingw32...
Installing RDoc documentation for mysql-2.8.1-x86-mingw32...

C:\Press_Play>gem install mysql2
Fetching: mysql2-0.2.6-x86-mingw32.gem (100%)
Successfully installed mysql2-0.2.6-x86-mingw32
1 gem installed
Installing ri documentation for mysql2-0.2.6-x86-mingw32...
Installing RDoc documentation for mysql2-0.2.6-x86-mingw32...

Navigate to the XAMPP install folder ->mysql ->bin (Generally C:\XAMPP\mysql\bin) and then copy the libmysql.dll file. Paste it in the Ruby install folder-> bin (Generally Ruby192/bin). Overwrite if you need to.

4. Run XAMPP and Start the MySQL service from the Control panel

5. Now it's time to put Hobo into action. Assuming your project name is Press Play (stop copying our project! :P ) and you too want to use MySQL, do the following

C:\Press_Play>hobo new Press-Play -d mysql
Hobo Command Line Interface 1.3.0.pre29
Generating Rails infrastructure...
create README
create Rakefile
create .gitignore
create Gemfile
create app
create app/controllers/application_controller.rb
create app/helpers/application_helper.rb
create app/mailers
create app/models
create app/views/layouts/application.html.erb
create config
create config/routes.rb
create config/application.rb
create config/environment.rb
create config/environments
create config/environments/development.rb
create config/environments/production.rb
create config/environments/test.rb
create config/initializers
create config/initializers/backtrace_silencers.rb
create config/initializers/inflections.rb
create config/initializers/mime_types.rb
create config/initializers/secret_token.rb
create config/initializers/session_store.rb
create config/locales
create config/locales/en.yml
create config/boot.rb
create config/database.yml
create db
create db/seeds.rb
create doc
create doc/README_FOR_APP
create lib
create lib/tasks
create lib/tasks/.gitkeep
create log
create log/server.log
create log/production.log
create log/development.log
create log/test.log
create public
create public/404.html
create public/422.html
create public/500.html
create public/favicon.ico
create public/index.html
create public/robots.txt
create public/images
create public/images/rails.png
create public/stylesheets
create public/stylesheets/.gitkeep
create public/javascripts
create public/javascripts/application.js
create public/javascripts/controls.js
create public/javascripts/dragdrop.js
create public/javascripts/effects.js
create public/javascripts/prototype.js
create public/javascripts/rails.js
create script
create script/rails
create test
create test/fixtures
create test/functional
create test/integration
create test/performance/browsing_test.rb
create test/test_helper.rb
create test/unit
create tmp
create tmp/sessions
create tmp/sockets
create tmp/cache
create tmp/pids
create vendor/plugins
create vendor/plugins/.gitkeep
apply C:/Users/navin/AppData/Local/Temp/hobo_app_template
gemfile hobo (>= 1.3.0.pre29)

Now is where Hobo shows it's strength... the Hobo Setup Wizard offers to run. Let's have a look at it shall we?

Hobo Setup Wizard
Do you want to start the Setup Wizard now?
(Choose 'n' if you need to manually customize any file before running the Wizard
You can run it later with `hobo g setup_wizard` from the application root dir.)
[y|n] y
=> "y"

Installing Hobo assets...
create app/views/taglibs/application.dryml
create public/stylesheets/application.css
create public/javascripts/dryml-support.js
create config/initializers/dryml_taglibs.rb
create app/models/guest.rb

First thing is Customizing the test framework. Let's leave that for later! So say n

Test Framework
Do you want to customize the test_framework? [y|n] n
=> "n"

Next up is a name for the user resource. If you;re writing a movie webapp, you may want to use the term "moviebuff" instead of "user".. For now, I'll stick with "user"

User Resource
Choose a name for the user resource: [<enter>=user|<custom_name>]
=> "user"

You know how those fancy sites send an activation email when you create a new account? or those sites which are invite only (Did someone say Google? :P )? Well, using Hobo, you can have both those features with complete ease!

Do you want to send an activation email to activate the user? [y|n] n
=> "n"

Invite Only Option
Do you want to add the features for an invite only website? [y|n] n
=> "n"

Since I'm comfortable with erb, I want to be able to use the erb templating system as well alongside the default dryml system. This can be done in the next step

Templates Option
Will your application use only hobo/dryml web page templates?
(Choose 'n' only if you also plan to use plain rails/erb web page templates) [y|
n] n
=> "n"

Hobo Rapid
Installing Hobo Rapid and default theme...
create public/javascripts/hobo-rapid.js
create public/javascripts/lowpro.js
create public/javascripts/IE7.js
create public/javascripts/ie7-recalc.js
create public/javascripts/blank.gif
create public/stylesheets/reset.css
create public/stylesheets/hobo-rapid.css
create public/hobothemes/clean
create public/hobothemes/clean/images/101-3B5F87-ACD3E6.png
create public/hobothemes/clean/images/30-3E547A-242E42.png
create public/hobothemes/clean/images/30-DBE1E5-FCFEF5.png
create public/hobothemes/clean/images/300-ACD3E6-fff.png
create public/hobothemes/clean/images/50-ACD3E6-fff.png
create public/hobothemes/clean/images/fieldbg.gif
create public/hobothemes/clean/images/pencil.png
create public/hobothemes/clean/images/small_close.png
create public/hobothemes/clean/images/spinner.gif
create public/hobothemes/clean/stylesheets/clean.css
create public/hobothemes/clean/stylesheets/rapid-ui.css
create app/views/taglibs/themes/clean
create app/views/taglibs/themes/clean/clean.dryml
create public/hobothemes/clean-sidemenu
create public/hobothemes/clean-sidemenu/images/100-ACD3E6-DBE1E5-H.png
create public/hobothemes/clean-sidemenu/images/100-DBE1E5-FCFEF5-H.png
create public/hobothemes/clean-sidemenu/images/300-3B5F87-ACD3E6-H.png
create public/hobothemes/clean-sidemenu/images/spinner.gif
create public/hobothemes/clean-sidemenu/stylesheets/clean-sidemenu.css
create app/views/taglibs/themes/clean-sidemenu
create app/views/taglibs/themes/clean-sidemenu/clean-sidemenu.dryml

Front Controller
Choose a name for the front controller: [<enter>=front|<custom_name>]
=> "front"
Installing front controller...
create app/controllers/front_controller.rb
create app/helpers/front_helper.rb
invoke test_unit
create test/unit/helpers/front_helper_test.rb
invoke test_unit
create test/functional/front_controller_test.rb
create app/views/front/index.dryml
remove public/index.html
route match 'search' => 'front#search', :as => 'site_search'
route root :to => 'front#index'
Installing 'user' resources...
create app/models/user.rb
invoke test_unit
create test/unit/user_test.rb
create test/fixtures/users.yml
insert app/models/user.rb
create app/mailers/user_mailer.rb
create app/views/user_mailer/forgot_password.erb
invoke test_unit
create test/functional/user_mailer_test.rb
create app/controllers/users_controller.rb
invoke test_unit

OK, it's all done. Let's take the site live shall we? Let's migrate our database schema to MySQL. As it;s been throughout, it's a completely hassle-free process. Just choose your database migration option as 'm'.

DB Migration
Initial Migration: [s]kip, [g]enerate migration file only, generate and [m]igrate: [s|g|m] m
=> "m"
rake db:setup
(in C:/Press_Play/Press-Play)
C:/Press_Play/Press-Pla/db/schema.rb doesn't exist yet. Run "rake db:migrate" to create it then try again. If you do not intend to use a database, you should instead
alter C:/Press_Play/Press-Play/config/application.rb to limit the frameworks that will be loaded

---------- Up Migration ----------
create_table :users do |t|
t.string :crypted_password, :limit => 40
t.string :salt, :limit => 40
t.string :remember_token
t.datetime :remember_token_expires_at
t.string :name
t.string :email_address
t.boolean :administrator, :default => false
t.datetime :created_at
t.datetime :updated_at
t.string :state, :default => "active"
t.datetime :key_timestamp
add_index :users, [:state]

---------- Down Migration --------
drop_table :users
create db/migrate/20110326174912_initial_migration.rb
rake db:migrate
(in C:/Press_Play/Press-Play)
== InitialMigration: migrating ===============================================
-- create_table(:users)
-> 0.2700s
-- add_index(:users, [:state])
-> 0.2450s
== InitialMigration: migrated (0.5180s) ======================================

Next up, the internationalization (I18n) option

The Hobo supported locales are de en es it pt-PT ru (please, contribute to more
Type the locales (space separated) you want to add to your application or <enter> for 'en':
=> "en"
create config/locales/hobo.en.yml
create config/locales/app.en.yml
remove config/locales/en.yml

Hobo even asks you if you want it to set up a git repository for your new project and git init it!

Git Repository
Do you want to initialize a git repository now? [y|n] n
=> "n"

Process completed!
You can start your application with `rails server`
(run with --help for options). Then point your browser to

Follow the guidelines to start developing your application.
You can find the following resources handy:

* The Getting Started Guide:
* Ruby on Rails Tutorial Book:

That's it! Really! Don't believe me? Check it out for yourself. Navigate to the folder Press-Play

C:\Press_Play>cd Press-Play

C:\Press_Play\Press-Play> rails server

C:\Press_Play\Press-Play>rails server
=> Booting WEBrick
=> Rails 3.0.5 application starting in development on
=> Call with -d to detach
=> Ctrl-C to shutdown server

Fire up your browser and key in http://localhost:3000 . And if everything has gone well, you should see:

Yeah, a site with user authentication, individual profiles and hashed passwords all ready for you, and you haven't written a single piece of code yet! The first account created is given administrator priviledges, and priveledges of all other accounts are decided by this account.

Now it's all about customizing it as per your preferences... Check out some of the sites that were born exactly as your project right now: ... Amazing eh?

I'd strongly suggest that you download Rapid Rails With Hobo, a free ebook of Hobo tutorials. Examples in the book make use of an older version of Hobo, so commands may not work out of the box, but it's still an excellent read! Also check out the Hobo cookbook for ideas on what can be achieved using Hobo.

Have fun with Hobo! :)

PS. The original plan was not to post on LoN this entire semester (a hiatus of sorts), but I just couldn't keep myself away! :)


Finally after all these years, here's to the beginning of what was there, what is there and hopefully what will remain!! So here are my thoughts & words -Online!!

Blog Archive