Meditations on programming, startups, and technology
Currently Browsing: Quick Tips

Typo and Lucid theme error

The Typo theme ‘Lucid’ seems to generate an error when used with the latest version (trunk) of Typo. In order to solve this, simply replace the following code in your /typo/themes/lucid/layouts/default.rhtml file: <%= render_component(:controller => 'sidebars/sidebar', :action => 'display_plugins') %> with <% benchmark "BENCHMARK: layout/sidebars" do %> <%=...

How to parse decimal numbers within a string

INPUT: a string containing decimal numbers. OUTPUT: an array containing all the decimal numbers within the given string. You can accomplish this task very quickly with the String#scan method and the right Regular Expression (regex). Given a string s, you can use: numbers = s.scan /[-+]?\d*\.?\d+/ numbers will be an array whose elements are the decimal numbers within the string s. Note how the regex considers the...

How to exclude an action from the controller’s layout processing

Sometimes you may want to exclude an action from being processed with the controller’s layout. In other words, you may need to use a default layout for all the methods in the controller, except for one of them. A quick way to do this is: class MyController < ApplicationController layout "mycontroller", :except =>...

Next Entries »

Copyright © 2005-2012 Antonio Cangiano. All rights reserved.