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
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.
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...
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...
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.)
Installing Hobo assets...
First thing is Customizing the test framework. Let's leave that for later! So say n
Do you want to customize the test_framework? [y|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"
Choose a name for the user resource: [<enter>=user|<custom_name>]
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
Invite Only Option
Do you want to add the features for an invite only website? [y|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
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|
Installing Hobo Rapid and default theme...
Choose a name for the front controller: [<enter>=front|<custom_name>]
Installing front controller...
route match 'search' => 'front#search', :as => 'site_search'
route root :to => 'front#index'
Installing 'user' resources...
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'.
Initial Migration: [s]kip, [g]enerate migration file only, generate and [m]igrate: [s|g|m] m
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.boolean :administrator, :default => false
t.string :state, :default => "active"
add_index :users, [:state]
---------- Down Migration --------
== InitialMigration: migrating ===============================================
-- add_index(:users, [:state])
== 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':
Hobo even asks you if you want it to set up a git repository for your new project and git init it!
Do you want to initialize a git repository now? [y|n] n
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: http://guides.rubyonrails.org/getting_started.html
* Ruby on Rails Tutorial Book: http://www.railstutorial.org/
That's it! Really! Don't believe me? Check it out for yourself. Navigate to the folder Press-Play
C:\Press_Play\Press-Play> rails server
=> Booting WEBrick
=> Rails 3.0.5 application starting in development on http://0.0.0.0:3000
=> 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: http://hobocentral.net/gallery/ ... 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! :)