Archive for the ‘Ruby’ Category

RESTful inplace edit plugin - quick fix

Thursday, November 20th, 2008

RESTful inplace edit plugin is now up-to-date. We merged a bugfix from Mina Guib to avoid broken URL’s if object overrides its own to_param method.

Thanks to Mina for her input.

method name of the day

Monday, September 22nd, 2008

I just stumbled over this method name: 


“reset_column_information_and_inheritable_attributes_for_all_subclasses” which does not have documentation.


Why should it. The name says everything. 

Time zones in Rails 2.1

Monday, September 1st, 2008

Rails 2.1 has pretty good support of Time Zones. It’s possible to save user-specific time zones. So if your users are from different zones, you can display the output in the corresponding zone of the user.
To set a default time zone, add config.time_zone in environment.rb. For the output, set the current time zone in before filters via application controller.

def set_zoneTime.zone = @user.time_zone if @userend

If you display timestamps in ActionMailer, you must set the Time.zone option within the ActionMailer class. Otherwise, the default settings of the database are taken (Time zone: UTC)

Rails provides nice helper methods to work with time zones. A useful method is in_time_zone(). It presents a time in any time zone.
>> t = Time.now
>> t.in_time_zone('Bern')=> Mon, 01 Sep 2008 14:47:00 +0200

Several rake task helps you to find out the possible zones:
rake time:zones:all
rake time:zones:local
rake time:zones:us

New Gem Released

Tuesday, August 26th, 2008

New ? Ah… not really. Would be fond to say that TLS support for ActionMailer is new. Anyway we packed up the code which is floating around on the web to add TLS support to pre Ruby 1.9 projects. Just for convenience. Find it on github.

The Ruby Language Will Reach 4 Million Programmers by 2013

Wednesday, August 20th, 2008

I missed this when it first came out. Gartner sees Ruby as a mayor player for the next five years. Unfortunately, Gartner sells the content they’re producing so normal people don’t get to see it. I came across a german translation where the main points are

  • 4 Million Ruby programmers by 2013
  • Focus on Convention over Configuration gives impressive functionality to developers
  • Rails-Framework is currently the killer app for ruby, other applications will follow
  • Domain Specific Languages will be the strongest attractor for professional developers
  • Tools will mature over the next year

There’s a graph of it somewhere on the web:

Gartner Ruby

Findings: The Ruby Language Will Reach 4 Million Programmers by 2013

Techworld - Ruby faces off against PHP, Java

Ruby Is on the Rise - Application Development

rwebthumb RubyGem updated

Tuesday, August 5th, 2008

We’ve added support for the Easythumb API to the rwebthumb gem. Just grab the latest version from github (sudo gem update simplificator-rwebthumb) and see the README. rwebthumb is a ruby wrapper for the Webthumb API.   

Resources:

We have two masters

Wednesday, July 30th, 2008

We are slowly moving our projects from our svn repository to github. In that process we had to move a private repository from one github account to another (pulling and pushing again), still maintaining the svn part.Funny situation ocurred today. After I pulled, merged and pushed my local repository back to the new github account I have two masters!I don’t exactly know how I did this. Who knows what I get when I pull the master branch now?Two masters on github Update: After I wrote this post, some background task seems to have tidied up for me. Phew. One master. 

Lighttp and Fileupload on Windows

Monday, July 14th, 2008

A customer of us deploys a Rails app on a Windows platform. We are using

It was a pretty straightforward process to setup and configure this stack, following one the online documentations. How happy we were when everything worked and we could hit our Rails app from the browser. Everything ? Ahhhh… not exactly. File upload did not work properly. Only one out of 10 uploads would succeed, the other would fail after around 60 seconds. The browser should an “Connection Timed Out” error message, the access and error logs of Lighty did not give much information.When we had IIS rewrite to one mongrel directly then the upload worked, so the problem was somewhere with Lighty. Digging around in the Lighttpd forums and documentation brought up following configuration options which could be relevant for fileupload:

  • server.max-request-size (defaults to 2 GB so there should be no problem)
  • server.upload-dirs (Make sure this is a valid Windows directory with write permissions)
  • server.network-backend (Unclear which backends are available for Windows)
  • server.max-read-idle (defaults to 360 seconds)
  • server.max-read-idle (defaults to 360 seconds)

We solved our problem by setting the server.network-backend to ‘writev‘ (a bit obscure but hey… it worked)

RubyGem for webthumb

Thursday, July 10th, 2008

Webthumb is a service to create thumbnails from websites (descriptive name, isn’t it…). It creates different sized thumbnails by default and you can request custom sizes.It offers an API to access it’s services and we wrapped up some code i wrote while on vacation and bundled it as a gem.The code is still a bit clumsy (as i wrote it on vacation :-) ) but it works nice for us. There is already another ruby wrapper for the API but it is not available as a RubyGem and does not expose some of the latest webthumb functionalities so we decided to write our own library. Josh gave us some extra credits so we could develop the API. Thanks. The gem is available on Simplificator’s github repo. To install do following:
sudo gem update --system (in case you are not yet on version 1.2.0 or higher)
sudo gem sources -a http://gems.github.com (only once)
sudo gem install simplificator-rwebthumb

To create thumbnails:
require 'rubygems'
require ‘rwebthumb’
include Simplificator::Webthumb
# main access point for the Webthumb API
wt = Webthumb.new(’YOUR API KEY HERE’)
job = wt.thumbnail(:url => ‘http://simplificator.com’)
job.write_file(job.fetch_when_complete(:large), ‘/tmp/test.jpg’)

For more info check the README file and (currently) the source code. All the features from a the request element are supported but currently not documented. I’ll look into that in some days.If you want to use the Gem you’ll need an account for webthumb. You’ll get 100 free credits every month so it’s easy to try it out.

on the edge

Sunday, June 22nd, 2008

Just a short note to direct you to a great post over at rubyonrails.com (some days old, i know…but i can not in the office right now and can not access the internet everyday. Yes… this exists :-) ). Chuw Yeo June wrote about API changes and performance tests. The API gets some new methods which make your life easier and at the same time are a bit confusing. Sample ? Here you go:

Object.present? method was added which is the same as not Object.blank? which is the same as Enumerable.any?

Three ways to do the same thing (as long as you are working on Enumerable). I think this is confusing and clutters the API.