Quick notes for installing libmemcached and Evan Weaver’s memcached gem, in case I forget (again):
- Get libmemcached source from http://tangent.org/552/libmemcached.html. Configure, make, make install. Make sure you get a version compatible with the Ruby memcached gem by opening the COMPATIBILITY file in the memcached gem files.
gem install memcached
- Create a symlink
ln -s /usr/local/lib/libmemcached.so.2 /usr/lib/.
- Try it out with
irb -rubygems, require 'memcached'
(0)
March 27th, 2008
It’s time again for some edge Rails love. If you haven’t listened to it yet, be sure to check out this week’s Rails Envy podcast
This week’s report covers changes from 17 Mar 2008 to 23 Mar 2008 (the day the corresponding Rails Envy podcast was recorded).
script/plugin install works for Git repositories
Yup you can now install plugins from Git repositories simply by running:
script/plugin install git://github.com/foo/kung_fu
What this really does is to clone a git repository (sans the entire git history by passing the —depth 1 option) into your plugins directory. If you’re looking for a Piston-like way to manage external Git repositories though, you’d still be better off with the development version of Piston (François Beausoleil, is posting frequently on his progress with adding Git support).
Credit goes to Jack Danger, a long-time Rails contributor for this patch.
Related changeset: http://dev.rubyonrails.org/changeset/9049
has_one :through
It’s been a long time coming - now you can do has_one :through (like has_many :through) for your join models. Ryan Daigle has example code on how to use it if you’re curious (though really, it’s just like has_many).
Credit goes to the Art of Mission guys and Chris O’Sullivan for pulling it all together.
Related changeset: http://dev.rubyonrails.org/changeset/9067
rake tasks time:zones:all, time:zones:us and time:zones:local
Some timezone-related rake tasks have been added to list the names of time zones recognized by the TimeZone class for the config.time_zone option you can put in your environment.rb. For example
rake time:zones:local
* UTC +08:00 *
Beijing
Chongqing
Hong Kong
Irkutsk
Kuala Lumpur
Perth
Singapore
Taipei
Ulaan Bataar
Urumqi
Credit: Geoff Buesing (core team member)
Related changeset: http://dev.rubyonrails.org/changeset/9074
#number_to_currency helper now supports a :format option
Now you can do something like:
number_to_currency(123.50, :unit => "£", :format => "%n %u")
# => 123.50 £
Instead of being stuck with the {currency_code} {amount} format which doesn’t work in some locales (such as “42 pounds”).
Related changeset: http://dev.rubyonrails.org/changeset/9052
March 22nd, 2008
After seriously giving Firefox 3 Beta 4 a try due to Safari 3.1 breaking the Shift key in Gmail (update: as kindly pointed out by some of my readers in the comments, it was Gmail that was broken, not Safari 3.1, doh), I’ve converted to using Firefox 3 Beta 4 as my primary browser. Before, I was using Firefox 2 as my main web browser, with a Safari window open for Gmail (because I tend to have around 50 tabs open in Firefox 2, and having Gmail among those tabs just kills Firefox 2’s performance). So yes, I was using Safari 3 as a “Gmail browser”, so to speak (in case you’d thought I’d defected from Firefox despite my history).
Anyway, enough with all that self-indulgent background - I’m writing this today to rave about how cool this one particular feature, auto-completion in the Location Bar (or the Address Bar, you know, where you type in URLs), in Firefox 3 is. Yes, you probably have already read about it and all the other neat new features and changes in Firefox 3, but I’d love to single out this one because it was the one thing I noticed that made browsing so much better when switching from Firefox 2.
So what is it? First, a screenshot of it in action:
Yup, typing into the Location Bar brings up a list of matched webpages from your browsing history. You can see from the screenshot that I entered “javascript” and it brought up not just URLs that started with “javascript” (which is the current Firefox 2 behavior), it also brought up URLs that contained “javascript” anywhere and even pages with titles containing “javascript”.
What’s the big deal? Well, one of the worst (”worst” being a relative adjective, relative to my opinion) things that can happen while looking for a page you once visited is forgetting its URL. If I’m lucky I can find it by bringing up the History sidebar in Firefox 2 and searching for it by some keyword or dredging through my browsing history.
In Firefox 3, I just need to type in some keywords related to the page and most likely it’d come up! Here’s how I start posting a new blog entry to this very blog:
No need to type “blog.c” and then selecting the correct page from the dropdown while remembering that the new post page is “post-new.php”. Less typing, no need to remember URLs. Just page titles and website names. If that isn’t useful for you, “you’re doing it wrong”. What’s more, Firefox 3 uses adaptive learning to keep an eye of what you’ve typed and what you select. After some time Firefox will learn from your choices and provide better suggestions in the autocomplete list. Sweet.
If you haven’t tried out Firefox 3 yet, go grab the latest beta. And then come back to this blog to get Firefox 2 and 3 running at the same time. I’m quite sure you’ll thank me for it (because this is not the only great feature in Firefox).
Update: Phil Wilson pointed to this extension for Firefox 2 that has the same auto-completion functionality.
March 20th, 2008
This week’s report covers changes from 10 Mar 2008 to 16 Mar 2008 (the day the corresponding Rails Envy podcast was recorded).
Custom JavaScript and stylesheet symbols
Remember how you can do something like:
javascript_include_tag :defaults
and Rails would load all the Prototype JavaScript files and your application.js?
You can now register your own custom expansion symbol too:
# In a Rails initializer.
ActionView::Helpers::AssetTagHelper.register_javascript_expansion :yui => ['yahoo', 'autocomplete', 'calendar']
# In your view.
javascript_include_tag :yui
would result in:
<script type="text/javascript" src="/javascripts/yahoo.js"></script>
<script type="text/javascript" src="/javascripts/autocomplete.js"></script>
<script type="text/javascript" src="/javascripts/calendar.js"></script>
You can do the same with the stylesheet_link_tag by registering a custom expansion symbol via register_stylesheet_expansion.
This is useful for anyone but in particular plugin developers who have a multiple asset files would appreciate being able to tell users to include JavaScript or stylesheets using a single symbol.
Warning: This patch currently breaks the default symbols like :all (check out the ticket for more info).
Related changeset: http://dev.rubyonrails.org/changeset/9016
Sexy default timestamps in migrations
Remember how you can say timestamps in a migration and Rails will create the ‘created_at’ and ‘updated_at’ columns for you? You can now also do add_timestamps :table_name and remove_timestamps :table_name in your migrations if you decide to add these columns later to a table:
def self.up
add_timestamps :posts
end
def self.down
remove_timestamps :posts
end
Related changeset: http://dev.rubyonrails.org/changeset/9014
ActiveRecord::Base#find(:last)
Just like Comment.find(:first), you can now do something like Comment.find(:last). There’s some controversy over whether this is bloat, but DHH makes a good case for it with this example:
class Person
has_many :comments, :order => 'created_at'
end
@some_person.comments.find(:last) # => Returns the most recent comment.
Related changeset: http://dev.rubyonrails.org/changeset/9012
Database rake tasks fixes
rake db:create used to ignore the ‘charset’ and ‘collation’ options in your database.yml configuration file. This has been fixed so that your created databases now respect those options.
rake db:drop and rake db:migrate:reset also no longer crash with an unhelpful exception if the database has already been dropped, and instead shows a proper error message.
Related changeset: http://dev.rubyonrails.org/changeset/9004
Rails’ logger now creates the log directory if it doesn’t exist
This is a blessing to those of us who use version control systems that don’t support empty directories (like Git). Rails’ default logger (the BufferedLogger), now creates a log/ directory if it doesn’t already exist. This should save you the step of creating/symlinking a log/ directory (or symlinking) on deploy.
Related changeset: http://dev.rubyonrails.org/changeset/9013
String#squish is faster
A faster implementation of the String#squish (and String#squish!) core extension has been committed.
Related changeset: http://dev.rubyonrails.org/changeset/9015
The #excerpt TextHelper no longer includes 1 character too many
Turns out that the #excerpt helper method was consistently including an extra character. This has been fixed.
Related changeset: http://dev.rubyonrails.org/changeset/9030
As usual, let me know of any inaccuracies or any suggestions you may have in the comments!
March 15th, 2008
Just a quick note to self. If you need to store Unicode and are using Sequel, make sure you:
- Create the database with a default charset of UTF8:
CREATE DATABASE my_db DEFAULT CHARSET utf8;. I think then any tables you create uses the default charset of utf8 unless otherwise specified.
- Pass an
:encoding option to Sequel’s MySQL adapter:
DB = Sequel.mysql 'my_db', :user => 'root', :password => '', :host => 'localhost', :encoding => 'utf8'
The Sequel documentation and wiki were quite unhelpful but reading code (see the connect method definition) always helps!