Archive for the ‘Web Development’ Category

Rack::Tidy and Devise in the Rack Middleware Stack

Saturday, September 25th, 2010

After quite a bit of digging around, and a little help from mr. Jose Valim at Plataformatec, I realized that the combination of the Devise authentication gem, along with Rack-Tidy, aren’t quite so friendly with each other. The main culprit here, I would say is the Tidy gem. Why? Because the essence of its existence is to re-arrange the markup handed back from the app-server. So some things get lost in the shuffle during all that house-cleaning (please, correct me if I’m wrong).

I had a hunch that with a little musical chairs in the middleware stack, we could find a solution that would allow all pieces to live harmoniously. Luckily, I was right. The trick is to make sure Tidy is inserted into the stack before ActionDispatch::Flash (because Rack::Tidy was killing the flash messages returned from Devise/Warden) and before Warden::Manager (the rack authentication layer beneath Devise). The resulting stack, for me, looks like so (important bits in bold):

use ActionDispatch::Static
use Rack::Lock
use ActiveSupport::Cache::Strategy::LocalCache
use Rack::Runtime
use Rails::Rack::Logger
use ActionDispatch::ShowExceptions
use ActionDispatch::RemoteIp
use Rack::Sendfile
use ActionDispatch::Callbacks
use ActionDispatch::Cookies
use ActionDispatch::Session::CookieStore
use ActionDispatch::ParamsParser
use Rack::MethodOverride
use ActionDispatch::Head
use ActionDispatch::BestStandardsSupport
use Rack::Tidy
use ActionDispatch::Flash
use Warden::Manager

use Sass::Plugin::Rack
run MyApp::Application.routes

And is accomplished with this code instead the app initialization process (application.rb):

config.middleware.delete ActionDispatch::Flash # remove from current position
config.middleware.insert_before Warden::Manager, ActionDispatch::Flash # add it right back in before Warden
config.middleware.insert_before ActionDispatch::Flash, Rack::Tidy, 'indent-spaces' => 2 # finally, add in Rack:Tidy before ActionDispatch::Flash.

The resulting stack looks like it’s working quite well for now.

Posted in Web Development | No Comments »

Debugging in Cucumber

Saturday, July 17th, 2010

As a relative newb’ to cucumber I realize there’s a lot to get caught up on. The one thing I do know is that there’s a lot that I don’t know. Having said that, when I run into a barrier or an issue and I want to dig into the source to figure things out, what do you do?

You break out ruby-debug, of course.

Add require ‘ruby-debug’ to features/support/env.rb and throw a breakpoint into your step definitions.

That’s all well and good, and it works just fine. But what do you look for while you’re in there? I spent the better part of an evening looking for how I could sniff around the html source cucumber was testing against and couldn’t find it. Lots of searching for how to pear into @response and @request – which end up being nil as far as I can see.

I had no idea.

Until I read this post from the LoED on how to test your source’s validity. In there was the answer:

page.body

Eureka!

Baby steps. I’ll figure this all out yet.

Posted in Web Development | 2 Comments »

rvm, ree, nginx and phusion passenger

Friday, March 12th, 2010

A production web / application server that I maintain has been around for mostly wordpress and static sites we host for some of our clients. Soon, however, the need for some Rails-based client sites will be popping up for us over there. Traditionally the set-up for those apps have been in clients’ own hosting environments, or were apps I hosted in a dedicated app-server slice of my own. So, the need crept up, and now I’m left planning for now, and the future. And what is that future, you might ask (ok, probably not)? Rails 3, of course.

The baseline reference implementation for Rails 3, as I know it, is 1.8.7, but has been tested to work with Ruby 1.9, and also functions properly with Phusion’s Ruby Enterprise Edition (henceforth known as REE). To say that Ruby is in a transition phase is an understatement. The community has been hard at work trying to get gems, frameworks, their associated plugins, etc, to work with all of the new shiny ruby-based toys. In order to accurately test, the RVM project has stepped up as the solution for testing and developing across multiple Ruby interpreters.

New server setup, quickly moving innovation, growth and change … all of these point me in one direction – drinking the RVM kool-aid and getting right into it. But not without a few hiccups. Here are my steps in getting things rolling with rvm, nginx, ree and passenger.

Note: Don’t install nginx at first thinking that passenger will end up being installed as a plugin, or module. I wasted some time in doing that. When you go through the process of installing passenger it’ll ask to compile and re-install nginx. So we’ll get to that eventually.

To get everything compiling as I wanted I had to install a handful of obvious, and not-so-obvious, packages and libraries. To wit:

sudo apt-get install ruby-full build-essential curl libpcre3 libpcre3-dev libpcrecpp0 libssl-dev zlib1g-dev libgcrypt11 libgcrypt11-dev bison libreadline5-dev

Your mileage may vary.

Also, the irony doesn’t escape me that we needed to install ruby, “ruby-full”, in order to install a bunch of other rubies. But hey, whatever.

Install rvm. It’s as easy as following the instructions at the RVM site. I chose to go the gem route. Follow the instructions as are given and things will be fine. The only hiccups I had involved some libraries that are taken care of in the above package installs.

Install the versions of ruby you’d like. rvm install 1.8.6,1.8.7-head,ree,1.9.1

According to fellow boston.rb’ist @techiferous we use 1.8.7-head, because

# Rails 3 needs Ruby 1.8.7. Use rvm to manage Ruby versions. Do “rvm ruby-1.8.7-head” NOT ruby-1.8.7-p249 (broken gems).

After some time compiling and wrangling everything together you should have a handful of different rubies at your disposal. Please visit the rvm site for examples, use cases and general information. It’s worth your time.

At this point I switched to ruby-ree in preparation of the passenger and nginx install. rvm ree. A quick ruby –version now tells us that we’re running ruby 1.8.7 (2009-12-24 patchlevel 248) [x86_64-linux], MBARI 0×6770, Ruby Enterprise Edition 2010.01.

Install Passenger and Nginx. gem install passenger && rvmsudo passenger-install-nginx-module will get you started. Here’s where the install of Nginx goes down, as noted in the text after you run the command:

Nginx doesn’t support loadable modules such as some other web servers do,
so in order to install Nginx with Passenger support, it must be recompiled.

I chose to customize my own install and selected the second option. Do whatever you’re most comfortable with. I prefer to have my compiled source in /opt/local, but again, it’s all a matter of preference. After some more compiling, we were all done and have a newly compiled install of Nginx, with Passenger, Utilizing the REE ruby interpreter.

Last but not least, go thank Wayne Seguin for the work on RVM. Amazing work!

Posted in Web Development | 1 Comment »

« Older Entries | Newer Entries »