config.scoping == :important => true
Chris Brandhorst ma 01 mrt 10
Last week I realised that using the config scope in your Rails environment files can be quite important.
We had the situation that we needed a different SMTP configuration for different environments.
In the environment.rb I found the following lines:
Rails::Initializer.run do |config| ... end ActionMailer::Base.smtp_settings = { :address => "127.0.0.1", :port => 25, :domain => "hollandonrails.nl" }
For the develoment environment I needed something else, so I proceeded to add the following to development.rb:
ActionMailer::Base.smtp_settings = { :address => "mail.google.com", :port => 25, :domain => "bla.com" }
But then the emails were not sent in the dev environment. Not knowing the cause, I spent an hour or two figuring this out.
Finally, I found out that the ActionMailer settings given in development.rb were not used. Some more investigation revealed the following things:
- ActionMailer is not defined within the Rails::Initializer block in environment.rb
- Using ActionMailer inside development.rb does NOT raise an error, but the scope of development.rb seems to be the same Rails::Initializer block
- Setting ActionMailer settings using config.action_mailer (like below) does allow overriding of these settings
config.action_mailer.smtp_settings = { :address => "127.0.0.1", :port => 25, :domain => "hollandonrails.nl" }
Gepost in | 0 reacties
jQuery voor Meisjes!
Gawin Dapper ma 01 mrt 10
Om de vrouwelijke opmars binnen onze ICT industrie verder te stimuleren is er nu een heuse cursus jQuery: is voor meisjes ontstaan. Ken je toevallig vormgeefsters, webdesigners of andere geïntereseerde, informeer ze dan omtrent deze cursus ;-)
$(document).ready(function(){ $(".girls").show(); });
Gepost in hor | 0 reacties
Let God help you!
Chiel Wester do 25 feb 10
Yesterday i posted about implementing Resque. With Resque you can easily implement background jobs and put them in a queue. After that, you can start some resque workers to do perform all the enqueued jobs.
Obviously there is a need to make sure that all your workers are running and when they go down (for any reason at all) you should be notified about it, and you want the workers to restart automatically.
In this case you can ask God for help. God is a monitoring tool written in ruby which makes it easy to implement. Simply install god with:
gem install god
The config files of god (in the config files you define the processes god needs to watch for you) are written entirely in ruby. After configuring your watches (see example on the god homepage) you need to start god and load the config file:
$ god $ god load /path/to/config/file
or shorter:
god -c /path/to/config/file
After that, you can ask god for the status of the processes it is watching (god status) and also restart processes (god restart name_of_group)
Resque ships with a predefined god configuration that can be found in the examples folder on GitHub.
In case you want to let god automatically restart your processes after a deploy, you can use the san_juan gem which is a capistrano plugin.

Gepost in hor | 0 reacties
Implementing Resque
Chiel Wester wo 24 feb 10
A while ago i posted an article with the announcement that Github’s new background worker library ‘Resque’ had made its way to the public community.
Now that i’m working with resque myself for some jobs, it’s time to give you a little summary of the way resque works and how you should implement it.
Background jobs
With resque, every Ruby class with a perform method can be used as a background job. So all you have to do to implement a background job is creating a class and add the self.perform method!
Remember that you need to set the queue name of the queue the job should be put in:
class Archive @queue = :queue_name ... def self.perform(args = {}) end end
Startup Redis
Before you can add any jobs to the queue, you need to start the queue manager for resque: redis. After installing redis, you can simply start is with the command ‘redis-server’.
Queueing jobs
To add a new job to the queue you simply need to make a call to Resque.enqueue with the class name of the job you want to enqueue and some additional arguments:
Resque.enqueue(Archive, arguments)
Keep in mind that it must be possible to marshal the additional arguments to json format! (This is because the queues of Resque are saved in json format in the redis server)
Now let’s do some work!
After adding jobs to the queue, all there’s left to do is start a worker to work through the queue and perform all the jobs you have put in the queues. This can be done with a simple rake task. First put the following line in the Rakefile of your application:
require 'resque/tasks'
After that, run the following command:
QUEUE=* rake environment resque:work
Workers for all existing queues will start and run all enqueued jobs!
Resque-web
With resque-web you can watch all running processes in resque. resque-web is a simple web interface that shows you information about queues, running workers and failed jobs. Just run ‘resque-web’ and open the url in your browser!

Gepost in hor | 0 reacties
Why You Should Be Grateful for Coding in Ruby
Dax Huiberts ma 22 feb 10
Wees blij dat je iedere dag in Ruby kan programmeren in plaats van in PHP. Het is voor mij een tijd geleden dat ik PHP code heb aangeraakt, maar ik weet wel dat als ik er al naar kijk, dat ik dan spontaan kiespijn krijg.
Kan jij jouw laatste keer nog herinneren dat jij PHP code heb geschreven? Hoe voelt dat? Pijnlijk hè?
Laten we daarom eens een momentje rust nemen om eens te realiseren dat we het eigenlijk goed te makken hebben en dat we heel trots mogen zijn met wat wij doen.
Denk je dat dit propaganda is? Nee joh, dit is gewoon een uiting van liefde. Wil je nog meer redenen hebben waarom Ruby zo tof is? Check dan deze 37 redenen voor onvoorwaardelijke Ruby liefde.
XOXO
Gepost in hor | 0 reacties
Passenger 2.2.10 released
Johan Vermeulen ma 22 feb 10
The guys at Phusion just released a bugfix version of Passenger with version number 2.2.10.
Part of the changelog:
- Fixed some Bundler compatibility problems.
- Fixed some file descriptor passing problems, which previously could lead to mysterious crashes.
- Fixed some compilation problems on newer GCC versions. Issue #430.
- Support #size method in rack.input.
Upgrading is easy:
gem install passenger passenger-install-apache2-module
And copy paste the snippet the installer generates into your apache configuration.
Gepost in hor | 0 reacties
Scottish Ruby Conference
Stephan Kaag do 18 feb 10
HollandOnRails crew members Paul, Dax, Chiel and myself will be attending this year’s Scottish Ruby Conference.
The Scottish Ruby Conference rebrands the successful Scotland on Rails conference. It is the same team organizing the same event that ran in 2008 and 2009, but with a more accurate name and an exciting new venue: The Royal College of Physicians in the centre of Edinburgh.
At this moment there are less than 15 tickets left for the event so be quick when you want to join the event or drink a whisky with the HoR crew.
The program.
Gepost in hor | 1 reactie
Editing gems
Gawin Dapper vr 12 feb 10
There are those days when you would like to edit the gem that you are using.
Usually, the best way is just to checkout the gem at github or gemcutter, but if you want to edit a specific version, or just a quicklook this can become somewhat time consuming.
Instead of searching the web for the source, you could always just look at your gem locally. Mine are installed at:
/Library/Ruby/Gems/1.8/gems/
But, there is, off course, also a gem to edit gems!
gem install gemedit
And then you can just edit your executing a command like this:
gem edit gemname
Sinds a lot of developers use textmate :
gem edit devise -e mate
Or you could just add $GEMEDITOR to your profile. If you have $EDITOR already set, it will pickup that, or fall back to vi if no editor is specified.
Gepost in | 0 reacties
ActiveRecord is nice, maar soms is raw SQL beter
Chris Brandhorst wo 10 feb 10
Met ActiveRecord heb je als Rails-ontwikkelaar een hoop nuttige methoden in handen om het werken met modellen en het aanpassen van een database te vergemakkelijken.
Het is echter niet altijd de snelste manier… AR voegt uiteraard een hoop overhead toe dat niet nodig is bij het uitvoeren van basale taken op de database, zoals in migrations.
Zo hadden wij een Customers-tabel met daarin een telefoonnummer en een mobiel telefoonnummer. Dit moest er 1 worden, en de mobiele telefoon had prevalentie. Dus wat doe je dan: je maakt een backup-kolom van de mobiele telefoon info, kopieert het originele mobiele nummer naar deze kolom en zet daarna het mobiele nummer gelijk aan het telefoonnummer als er geen mobiel nummer was. In de AR-based migration staat dan het volgende:
add_column :customers, :mobile_number_old, :string, :length => 50 Customer.reset_column_information Customer.all.each do |c| c.mobile_number_old = c.mobile_number c.mobile_number = c.phone_number if c.mobile_number.nil? || c.mobile_number.strip.blank? c.save end
Ziet er goed uit. Echter, op de tabel met 33.100 records was de migration na 10 minuten nog niet klaar.
Een andere aanpak was nodig, dus werd gewoon raw SQL geprobeerd:
add_column :customers, :mobile_number_old, :string, :length => 50 execute "UPDATE customers SET mobile_number_old = mobile_number" execute "UPDATE customers SET mobile_number = phone_number WHERE mobile_number IS NULL OR TRIM(mobile_number) = ''"
Deze query was na 3 seconden klaar.
Probeer dus goed te bedenken of je een operatie op grote aantallen records niet beter met raw SQL kan doen!
Gepost in hor | 3 reacties
map.resources :rails, :version => 3.0, :stage => "beta"
Paul Engel zo 07 feb 10
Het zijn hectische dagen binnen de Ruby On Rails wereld. De komst van Rails 3.0 brengt veel informatie-uitwisseling met zich mee.
Maar “Waar te beginnen?” denk je dan. Gelukkig heeft RubyInside al een hele hoop zoekwerk voor de Rails community verricht naar allerlei resources betreft Rails 3.0 (beta). Een paar links uit de uitgebreide lijst:
- Rails 3.0 Release Notes – Welbekend inmiddels
- The Path to Rails 3 – Een uitstekende guide om aan de slag te gaan met Rails 3
- RailsPlugins.org – Zoek en verifieer of een plugin / gem in Rails 3 nog werkt
- Unobtrusive JavaScript in Rails 3 – Een oude, maar ook een goede artikel over een nette implementatie van Javascript (binding) binnen Rails 3
Het zijn er in totaal 36! Dus check ze uit.
Gepost in hor | 0 reacties
Welkom op Holland On Rails
Het startpunt voor Ruby On Rails in Nederland. Vind de laatste technieken, meningen en nieuwtjes.Recente Jobs
Gezocht: Ruby On Rails ontwikkelaar (junior of senior)
Eet, drink en droom jij over Ruby On Rails? Wil jij het liefste dag en nacht bezig zijn met jehobby; super coole webapplicaties ontwikkelen in Ruby On Rails?
Dan willen wij jou graag een podium bieden om je Ruby skills te vertonen aan onze nationale en internationale klanten!
@ Internetbureau Holder, Obdam
Bekijk alle jobs »»
Gereedschapskist
Onmisbare tools vooriedere developer!
- Ruby On Rails
Framework voor de web 2.0 developer. Eindelijk vooruitgang! - TextMate
Editor for true pro's
Typ, tab, top :-)
Nee, niet voor Win. - Made On A Mac
En nou is het over met die saaie grijze Windows bak van je!
Auteurs op deze site
Chris Obdam
'Less is more' evangelist, past dit ook dagelijks toe op zijn tandenborstel.Chiel Wester
Snelheidswonder op Ruby wielen. Leuk om mee te pair-programmen ;-)