I've finally decided to test the "Padrino" waters again. I've heard a lot of good things about it lately, and a recent benchmark blew my fucking mind. So here I am, looking at the website, in my terminal, and with an editor open. A word about Padrino first: It's not an MVC framework, despite what the website says and how familiar that architecture feels. It's actually a PAC, and it would do you well to remember this when using Padrino.
My first step of course, was to make a directory for my project. Since I didn't know if I'd like Padrino, this time, I figured I might want to try out multiple ideas. This means making a whole
padrino directory in my
~/repo/ruby/ path. Having done so I then made the project directory (
~/repo/ruby/padrino/cloudname) so that I'd have a place to put my
.rvmrc. Specifically this is so I could install Padrino into the cloudname gemset.
Having made the
padrino directory, the
cloudname directory, and the
rvm --create --rvmrc 1.9.2@cloudname (and cleaning up the extra rc file) I went on to install Padrino. To do this I looked at the website instructions which promptly told me to use
gem install padrino. No sight of anything related to Bundler, which will probably annoy me. The resulting output is as follows:
krainboltgreene on MacMini.local in ~/repo/ruby/padrino/cloudname$ gem install padrinoFetching: tilt-1.3.2.gem (100%)Fetching: rack-1.3.2.gem (100%)Fetching: sinatra-1.2.6.gem (100%)Fetching: url_mount-0.2.1.gem (100%)Fetching: http_router-0.9.7.gem (100%)Fetching: thor-0.14.6.gem (100%)Fetching: activesupport-3.0.9.gem (100%)Fetching: padrino-core-0.10.1.gem (100%)********************UPGRADE NOTESWhen upgrading, please 'enable :sessions' for each application as shown here: http://bit.ly/kODKMxWhen upgrading, please 'register Padrino::Rendering' for each application as shown here: https://gist.github.com/1d36a35794dbbd664ea4********************Fetching: i18n-0.5.0.gem (100%)Fetching: padrino-helpers-0.10.1.gem (100%)Fetching: mime-types-1.16.gem (100%)Fetching: polyglot-0.3.2.gem (100%)Fetching: treetop-1.4.10.gem (100%)Fetching: mail-2.3.0.gem (100%)Fetching: padrino-mailer-0.10.1.gem (100%)Fetching: bundler-1.0.17.gem (100%)Fetching: diff-lcs-1.1.2.gem (100%)Fetching: grit-2.4.1.gem (100%)Fetching: padrino-gen-0.10.1.gem (100%)Fetching: padrino-cache-0.10.1.gem (100%)Fetching: padrino-admin-0.10.1.gem (100%)Fetching: padrino-0.10.1.gem (100%)Successfully installed tilt-1.3.2Successfully installed rack-1.3.2Successfully installed sinatra-1.2.6Successfully installed url_mount-0.2.1Successfully installed http_router-0.9.7Successfully installed thor-0.14.6Successfully installed activesupport-3.0.9Successfully installed padrino-core-0.10.1Successfully installed i18n-0.5.0Successfully installed padrino-helpers-0.10.1Successfully installed mime-types-1.16Successfully installed polyglot-0.3.2Successfully installed treetop-1.4.10Successfully installed mail-2.3.0Successfully installed padrino-mailer-0.10.1Successfully installed bundler-1.0.17Successfully installed diff-lcs-1.1.2Successfully installed grit-2.4.1Successfully installed padrino-gen-0.10.1Successfully installed padrino-cache-0.10.1Successfully installed padrino-admin-0.10.1Successfully installed padrino-0.10.122 gems installed
After carefully reading the documentation on the various generators, including the project generator, I decided on using this setup:
padrino generate project cloudname --orm mongoid --test riot --script jquery --renderer slim --mock rr --stylesheet compass
Which denotes a mongoid orm, riot test suite, jquery library, slim html renderer, and rr for mocking. It produced this output:
It should be noted that I attempted to run the command in
~/repo/ruby/padrino/cloudname/ with the -r option set to
../cloudname. Instead of building the project in my current directory it built it in
At this time I started my MongoDB instance, on the 127.0.0.1:28017 address/port. Following the instructions I moved into the cloudname directory and ran
krainboltgreene on MacMini.local in ~/repo/ruby/padrino/cloudname$ bundle installFetching source index for http://rubygems.org/Installing rake (0.9.2)Installing activesupport (3.0.9)Installing builder (2.1.2)Installing i18n (0.5.0)Installing activemodel (3.0.9)Installing bson (1.3.1)Installing bson_ext (1.3.1) with native extensionsUsing bundler (1.0.15)Installing chunky_png (1.2.1)Installing fssm (0.2.7)Installing sass (3.1.7)Installing compass (0.11.5)Installing diff-lcs (1.1.2)Using mime-types (1.16)Installing grit (2.4.1)Installing rack (1.3.2)Installing url_mount (0.2.1)Installing http_router (0.9.7)Installing polyglot (0.3.2)Installing treetop (1.4.10)Installing mail (2.3.0)Installing mongo (1.3.1)Installing tzinfo (0.3.29)Installing mongoid (2.1.7)Installing tilt (1.3.2)Installing sinatra (1.2.6)Using thor (0.14.6)Installing padrino-core (0.10.1)Installing padrino-helpers (0.10.1)Installing padrino-admin (0.10.1)Installing padrino-cache (0.10.1)Installing padrino-gen (0.10.1)Installing padrino-mailer (0.10.1)Installing padrino (0.10.1)Installing rack-flash (0.1.2)Installing rack-test (0.6.1)Installing rr (1.0.3)Installing riot (0.12.4)Installing temple (0.3.2)Installing slim (1.0.1)
So all of my gems installed just fine, from the auto-generated gemfile. Almost every tutorial and article talks about the Padrino admin interface that ships with Padrino, so I had to try that out first:
krainboltgreene on MacMini.local in ~/repo/ruby/padrino/cloudname$ padrino g adminforce .componentscreate adminexist admincreate admin/controllers/base.rbcreate admin/controllers/sessions.rbcreate public/admincreate public/admin/stylesheets/base.csscreate public/admin/stylesheets/themes/amro/style.csscreate public/admin/stylesheets/themes/bec-green/style.csscreate public/admin/stylesheets/themes/bec/style.csscreate public/admin/stylesheets/themes/blue/style.csscreate public/admin/stylesheets/themes/default/style.csscreate public/admin/stylesheets/themes/djime-cerulean/style.csscreate public/admin/stylesheets/themes/kathleene/style.csscreate public/admin/stylesheets/themes/olive/style.csscreate public/admin/stylesheets/themes/orange/style.csscreate public/admin/stylesheets/themes/reidb-greenish/style.csscreate public/admin/stylesheets/themes/ruby/style.csscreate public/admin/stylesheets/themes/warehouse/style.csscreate admin/app.rbappend config/apps.rbapply orms/mongoidapply tests/riotcreate models/account.rbcreate test/models/account_test.rbcreate admin/views/accountscreate admin/controllers/accounts.rbcreate admin/views/accounts/_form.slimcreate admin/views/accounts/edit.slimcreate admin/views/accounts/index.slimcreate admin/views/accounts/new.sliminsert admin/app.rbforce models/account.rbcreate db/seeds.rbexist admin/controllersexist admin/viewscreate admin/views/basecreate admin/views/layoutscreate admin/views/sessionscreate admin/views/base/_sidebar.slimcreate admin/views/base/index.slimcreate admin/views/layouts/application.slimcreate admin/views/sessions/new.sliminsert admin/app.rbinsert Gemfilegsub admin/views/accounts/_form.slimgsub admin/controllers/accounts.rb=================================================================The admin panel has been mounted! Next, follow these steps:=================================================================1) Run 'padrino rake seed'2) Visit the admin panel in the browser at '/admin'=================================================================
I proceded to follow the instructions and ran into my second problem with Padrino:
krainboltgreene on MacMini.local in ~/repo/ruby/padrino/cloudname$ padrino rake seedCould not find gem 'bcrypt-ruby (>= 0)' in any of the gem sources listed in your Gemfile.Run `bundle install` to install missing gems.
First thing I do is check for
krainboltgreene on MacMini.local in ~/repo/ruby/padrino/cloudname$ gems | grep bcrypt
With zero results returned, as you can see. I've dealt with these kinds of problems before in Rails, though so I thought to follow the error messages instructions first. Suddenly, everything is working:
krainboltgreene on MacMini.local in ~/repo/ruby/padrino/cloudname$ bundle install | grep bcryptInstalling bcrypt-ruby (2.1.4) with native extensionskrainboltgreene on MacMini.local in ~/repo/ruby/padrino/cloudname$ gems | grep bcryptbcrypt-ruby (2.1.4)
So it's time to get back to the original task, of seeding the database:
krainboltgreene on MacMini.local in ~/repo/ruby/padrino/cloudname$ padrino rake seed=> Executing Rake seed ...Which email do you want use for logging into admin? email@example.comTell me the password to use: ***Sorry but some thing went wrong!- Password is too short (minimum is 4 characters)
What an interesting twist, having a command line client to handle the admin account. Though I'm not really liking the 4 minimum, I can understand it. Lets try this again:
krainboltgreene on MacMini.local in ~/repo/ruby/padrino/cloudname$ padrino rake seed=> Executing Rake seed ...Which email do you want use for logging into admin? firstname.lastname@example.orgTell me the password to use: hqw7KsJ3cgfu9KsV8rP66xrcN=================================================================Account has been successfully created, now you can login with:=================================================================email: email@example.com: hqw7KsJ3cgfu9KsV8rP66xrcN=================================================================
Much better! The second listed task is to visit the
/admin path on the app. Of course that means I need to start Padrino, which means setting up Pow (hopefully)! To do this I use my ever faithful
powder gem, with the command:
krainboltgreene on MacMini.local in ~/repo/ruby/padrino/cloudname$ powderYour application is now available at http://cloudname.dev/krainboltgreene on Kurtis-Rainbolt-Greenes-Mac-mini.local in ~/repo/ruby/padrino/cloudname$ powder open# This is where the browser opens up to http://cloudname.dev/
Since I don't have a "proper" Padrino application it amusingly shows me the default Sinatra error page:
The example in the middle of the page doesn't really make sense from Padrino's standpoint, as far as I know. While being built on Sinatra, you can't just declare a route anywhere. I was on a mission, though, and I wanted to check out this admin interface. After intering the
/admin path I was served this login page:
The first thing that hit me was that "Bypass Login?" checkbox. I mean I know it's an admin interface, but was "Remember me?" too standard? In anycase logging in was a breeze, but the admin interface wasn't:
Lots of Ipsum Lorem, as you can see in that image. Nothing really stands out as important except random highlights. Nothing really seems like a set of controls, either. I could be looking at any old wordpress template.
Going to the
/admin/accounts/edit/:id path showed me my admin account, with a few fields. Classic splitting of First Name and Last Name, where there doesn't need to be:
Having figured out that Padrino works fine so far I decided to finally initiate a git instance. I could probably skip this part, but some of you probably haven't used Git Flow and if I can introduce you to it, all the better. So lets get this party started:
So lets talk about this application before we go further. BrowserID is a new technology that implements Verified Email Protocol. You can read more at the website here. CloudName is going to be a Ruby version of that server, so we'll need at the very least accounts for users to sign in with. Accounts happens to need all three of the core PAC parts: Presentation (Commonly called a View), Abstraction (Sometimes called a Model), and Controller (You probably know this one). This'll let us explore Padrino completely, from start to finish.
Since this application is heavily focused on "Authentication" the top level application will be where the account resource resides. Padrino has already created two applications so far:
admin/. So we'll need to dig into
app/ and create the Account resource.