rescue Resque
Chiel Wester wo 14 jul 10
A couple of months ago, i posted an article on this blog about implementing resque for performing background jobs.
There have been several updates to the resque core since then, one of them is the possibility to write plugins for resque without having to change the main functionality of resque.
One of these plugins that was created is resque-retry. When you include this plugin in your Job class, any failed job will be retried several times when it raises an error. This becomes very useful when your job uses some external service that can give the pain of timeouts.
The plugin also has the possibility to only retry on specific exceptions (e.g. Timeout, NetworkError). At the moment the job is simply deleted when the retry limit is exceeded. Of course you could overwrite this functionality to notify you in some way that a job failed too many times:
def on_failure_retry(exception, *args)
if retry_criteria_valid?(exception, *args)
try_again(*args)
else
# Notify me about this error!
Resque.redis.del(redis_retry_key(*args))
end
end
Check for examples and documentation the github project page
This plugin depends on the resque-scheduler plugin that gives you the possibility to schedule jobs in a cron-like way or to schedule a job at some time in the future.
Gepost in hor | 0 reacties
Humanizer: web_user.verify()
Paul Engel ma 12 jul 10
As a web developer, you are often forced to participate in the struggle against bots submitting bogus data to your web application. The most common implementation are Captcha images which contain distorted digits and letters you will have to fill in for verification.
Kisko Labs has provided us a Rails 3 gem to use instead and it’s called Humanizer. This gem implements the question and answer method for verifying you being human. Its installation and implementation is child’s play (both 2-liners).
Humanizer supports internationalization with i18n and is shipped with a set of questions and answers in English, German and Finnish. You can your own Q&A’s of course.
To see Humanizer in action, visit the ArcticStartup sign up page. All in all, it’s a very useful and simple gem!
Gepost in hor | 0 reacties
Private attachments with paperclip
Johan Vermeulen vr 09 jul 10
Aaron Sumner of Everyday Rails wrote a nice article about howto make attachments private.
Only I recommend to use the send_file method provided by the rails framework with the x_sendfile header. This prevents the ruby process from streaming the file to the client, instead let the webserver software handle it (X-SendFile is disabled by default).
Gepost in hor | 0 reacties
Ruby 1.9.2 RC1 is released
Stephan Kaag do 08 jul 10
A few days ago Ruby 1.9.2 RC has been released. This is a release candidate of Ruby 1.9.2.
Ruby 1.9.2 is mostly compatible with Ruby 1.9.1 except for some changes listed here.
Both Array and Enumerable are extended with new possibilities for handling them. The most interesting changes are summed up overhere.
The upcoming Rails 3 release is compatible with Ruby 1.9.2.
Gepost in hor | 0 reacties
Browser testing web apps
Jeroen Bulters wo 07 jul 10
We all know that full-stack integration tests for Rails applications can be quite cumbersome. Luckily, we have tools like watir and selenium. The major drawback to these tools is that it’s not easy to quickly whip up a test for something your “just trying out”. In other words: It takes the fun out of testing.
Most of the times we then result to manual – in browser – testing. But – being human and all – this leads to inconsistent – and therefore possibly -incorrect testing. Meet Fake, a web browser automation app (Mac only!).
Fake is built on the Fluid site specific browser application and supports native Applescript scripting which makes it easy to perform a wide variety of tasks (including uploading files, which can be a hassle with other tools).
Having played with Fake last night (after seeing the Dutch soccer team reach the WorldCup final) I can only say that this application will become a regular in my development toolchain.
Gepost in hor | 1 reactie
Writing more with less
Roy van der Meij wo 30 jun 10
So you would like to use variables and inheritance with css? Now you can! With less.js.
So what is less?
With less you can do exactly what I stated above. Let’s check out some code.
@brand_color: #4D926F; #header { color: @brand_color; } h2 { color: @brand_color; }
How awesome is that :)
But what I like more is the inheritance part.
#header { color: red; a { font-weight: bold; text-decoration: none; } }
Right now less is a gem and a plugin for rails, but they rewritten it entirely in javascript. So you can now use it without any use of a backend.
Just place this in your head tag.
<link rel="stylesheet/less" href="style.less" type="text/css" /> <script src="http://lesscss.googlecode.com/files/less-1.0.21.min.js"></script>
And have fun in your stylesheets/style.less file :-)
For more info check out these links:
lesscss.org
less.js on github
less tutorial
Gepost in hor | 1 reactie
Using rails3 safely without rvm
Wijnand Wiersma wo 30 jun 10
Currently installing rails3 will cause some breakage to older rails apps and you can’t easily generate a new rails 2.3 app.
One possible solution to this is rvm but I like to use my one and only REE installation instead.
So I decided to use some bundler magic to install rails only within the bundler bubble.
Currently I don’t have any rails3 gems installed:
yaya 22:29:~: $ gem list | grep rails autotest-rails (4.1.0) rails (2.3.5, 2.3.4) rspec-rails (2.0.0.beta.8, 1.2.9) yaya 22:29:~: $ which ruby /opt/ruby/bin/ruby
So I create a directory (just to be clean) and add a Gemfile:
yaya 22:29:~: $ mkdir to_bundle yaya 22:30:~: $ cd to_bundle yaya 22:30:~/to_bundle: $ vi Gemfile yaya 22:30:~/to_bundle: $ cat Gemfile source 'http://rubygems.org' gem 'rails', '3.0.0.beta4'
Now I run bundle install to add rails3 to the bundler bubble:
yaya 22:30:~/to_bundle: $ bundle install Fetching source index from http://rubygems.org/ Using rake (0.8.7) from system gems Using abstract (1.0.0) from system gems Using activesupport (3.0.0.beta4) from system gems Using builder (2.1.2) from system gems Using i18n (0.4.1) from system gems Using activemodel (3.0.0.beta4) from system gems Installing erubis (2.6.6) from rubygems repository at http://rubygems.org/ Using rack (1.1.0) from system gems Installing rack-mount (0.6.6) from rubygems repository at http://rubygems.org/ Using rack-test (0.5.4) from system gems Using tzinfo (0.3.22) from system gems Using actionpack (3.0.0.beta4) from system gems Using mime-types (1.16) from system gems Using polyglot (0.3.1) from system gems Using treetop (1.4.8) from system gems Installing mail (2.2.5) from rubygems repository at http://rubygems.org/ Using actionmailer (3.0.0.beta4) from system gems Using arel (0.4.0) from system gems Using activerecord (3.0.0.beta4) from system gems Using activeresource (3.0.0.beta4) from system gems Using bundler (0.9.26) from system gems Installing thor (0.13.7) from rubygems repository at http://rubygems.org/ Using railties (3.0.0.beta4) from system gems Installing rails (3.0.0.beta4) from rubygems repository at http://rubygems.org/ Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
Cool, but the rails command in my $PATH is still the rails 2.3 version. Let’s ask bundler to run the rails3 beta to generate a new app:
yaya 22:32:~/to_bundle: $ bundle exec rails new ../new_app create create README create Rakefile create config.ru create .gitignore create Gemfile create app ...... lots more output
Now when I enter my new app directory I can use all the new rails commands, I just have to prepend it with bundle exec.
I am sure you will add some shell aliases to save some keystrokes.
yaya 22:33:~/new_app: $ bundle exec rails c Loading development environment (Rails 3.0.0.beta4) irb(main):001:0>
So, this way I can use rails 2.3 the way I did and I don’t have to manage multiple ruby installations with their own gem sets.
Gepost in hor | 0 reacties
and vs &&
Chiel Wester wo 30 jun 10
Last week we had a discussion about using the ‘and’ operator vs the ‘&&’ operator for equasions. The only reason to prefer ‘and’ above ‘&&’ would be that people say the code will be better readable and cleaner.
Although the code might be better readable, you have to be careful using the ‘and’ operator because it has a slightly different behaviour than the && operator. In this article you can see a very good example of this difference.
So, when using the and operator, make sure you put brackets around the equasion to prevent strange behaviour! If you don’t want to use the brackets, just use && this will save you from a lot of trouble
Gepost in hor | 0 reacties
PDFKit
Dax Huiberts di 29 jun 10
Another new kid in town. This time it is PDFKit, a new tool for generating PDF documents in your Rails application.
Before this we had two main choices. Either use PrinceXML with the princely gem to convert your HTML documents + CSS stylesheets to PDF while paying a hefty server license of $3,800. Or use Prawn and build your PDF documents using nothing but Ruby code. I once thought Prawn was actually a nice tool, but I was amazed by the inordinate amount of code needed to display a simple table.
Here comes PDFKit, a new tool to create your PDF documents using HTML + CSS again. It’s build on the Webkit HTML engine, so you’ll get fine rendering and you don’t have to pay an excessive server license.
Go check out this Railscast on PDFKit.
Gepost in hor | 0 reacties
nifty rails 3.0 methods II
Daniel Willemse zo 27 jun 10
@Wijnand,
I have to agree with you, in that class methods you describe can do the same the scopes can. The only reason I can think of, is the one you would reject.
Now for the new methods I made a post on about a week ago.
I thought to myself, what would happen if i wrote a class method “order” and tried to use it on the class.
Here’s what I tried:
Class Invoice < ActiveRecord::Base def self.order return "new class method" end end
Now, when I tried this in the console
with
>> Invoice.order
I got the expected “new class method” string returned.
With
>> Invoice.order.where("id = ?", 1)
I got
NoMethodError: undefined method `where’ for new class method
Which was not unexpected.
However, when I tried Invoice.where(“id = ?”, 1).order
It returned the active record relation as if ignoring my own class method.
Keep this in mind when (for whatever reason you may have) overriding
certain class methods like order or where. Should you want to use your order method over the pre-defined rails one, you need to put that method first in line on your model like
Model.own_order_method.where(“arguments”)
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 ;-)