Clearing Memcached at Capistrano Deployment

Capistrano, Ruby on Rails No Comments »

It’s a two step process:

1. Create a rake task (in lib/tasks/clear_memcached.rake for example):

namespace :cache do
  desc ‘Clear memcache’
  task :clear => :environment do
    ActionController::Base.cache_store.clear
  end
end

2. In deploy.rb add the following:

namespace :cache do
  desc “Clear memcach after deployment”
  task :clear, :roles => :app do
    run “cd #{current_release} && rake cache:clear RAILS_ENV=production”
  end
end

and (depending on your task chain):

after “deploy:update_code”, “cache:clear”

Hope it helps.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

CSS Specificity Algorithm Table from Evan Sharp’s Mix 2010 talk

CSS No Comments »

Having watched Evan Sharp’s “Comp to Code” talk at Mix 2010 video (check out the other Mix videos also, most are excellent), searching the web for the CSS specificity algorithm table turned up nothing as simple as his pseudo-decimal algorithm. So I reproduced the table from the talk verbatim here for reference. As you can see, id selector elements will dramatically increase the specificity of the selector, while class selector elements are an order of magitude less specific:

CSS specificity algorithm table

selector

id

class

element

sum

#logo

1 0 0 100

.header .nav li

0 2 1 21

.header h1#logo

1 1 1 111

div div * a:hover

0 0 4 4

#nav img#logo

2 0 1 201

Exercise for the reader: Say “specificity” three times fast. Extra points: Say “specificity algorithm” three times fast.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Thailand 2010, Moving Forward?

Thailand No Comments »

A great overview of the current political situation in Thailand and its roots, from long term on-the-ground experience in Thailand and conversations with Thais from all walks of life, which I think is essential. 

I agree on most counts, especially the view of Abhisit and his (in)ability to bring about reconciliation, and I also hope for a good outcome over the next few years. However, I’m slightly more sceptical that the outcome can be peaceful.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

odd number of arguments for Hash (ActionView::TemplateError)

Ruby on Rails 1 Comment »

This error can be caused by an outdated version of the globalize2 plugin, so try

 script/plugin remove globalize2

and

script/plugin install git://github.com/joshmh/globalize2.git

Hope it helps.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

RSpec and Webrat for Rails Integration Testing

RSpec, Ruby on Rails, Webrat No Comments »

Getting RSpec and Webrat to cooperate has gotten a bit easier recently, so make sure you have all the latest versions of the webrat, rspec and rspec-rails gems installed. Some quirks remain which might trip you up coming from TestUnit. For example if you

cd spec/integration

and

spec ./user_integration_spec.rb

or

ruby ./user_integration_spec.rb

you might get

undefined method `visit (…)

while a similar procedure would run fine in test/integration with TestUnit

But with RSpec, when you run

spec ./spec/integration/user_integration_spec.rb

or

rake spec:integration

all is well. It seems you have to stand at least in the spec directory or above, otherwise the block

Webrat.configure do |config|
  config.mode = :rails
  config.open_error_files = false # prevents webrat from opening the browser
end

in spec_helper.rb will not run correctly.

So remember that RSpec is a bit less forgiving than TestUnit in how your tests are called.

It’s also important that you run

script/generate rspec

after installing RSpec to have the rake tasks “installed”.

Finally, his procedure will likely not be necessary with recent versions of Webrat and RSpec.

See here for a testing system for Rails that integrates RSpec and Webrat, it makes a  lot of sense.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]
WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in