Currently the posts are filtered by: Ruby on Rails
Reset this filter to see all posts.

Category: Ruby on Rails
Date: 2013-07-12 16:04

Use Delayed Job with Devise mailers

In order to have Devise send its emails by background process application Delayed Job just include one line of code after your Devise declaration in your user model. Devise uses one method for all mailers. So all modules make use of it, including extensions like DeviseInvitable (check their code for this method!).

Code:  Select all
class User < ActiveRecord::Base
  devise :database_authenticatable, :recoverable, :lockable, :trackable, :timeoutable, :invitable
  # Use delayed job to send emails from Devise and DeviseInvitable
  handle_asynchronously :send_devise_notification, :queue => 'devise'

Tested on Rails 3.2.13 with Devise 2.2.4 and Delayed Job 3.0.5

Category: Ruby on Rails
Date: 2012-05-04 22:45

Using SimpleCov with FactoryGirl

FactoryGirl is a great replacement for your Ruby-on-rails fixtures. They offer more flexibility for generating stubs and mack-ups for your automated testing.

SimpleCov is the test coverage tool for Ruby 1.9.x (Use RCov for Ruby 1.8.x).

Using both in conjunction requires two extra lines in your test/test_helper.rb file not covered by any documentation. This will prevent you from getting messages like "Factory not registered: " or "uninitialized constant Test::Unit::TestCase::FactoryGirl (NameError)".

My test_helper.rb file looks like:

Code:  Select all
require 'simplecov'
SimpleCov.start 'rails'
ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
# The following two lines of code will reinitialize Factorygirl:
require 'factory_girl'
class ActiveSupport::TestCase
Category: Ruby on Rails
Date: 2010-08-20 23:06

HTML5 helpers for Rails 2.3.x

Eager on using HTML5 in your Rails projects without upgrading to Rails 3?

For those I've ported the HTML5 FormHelpers and FormTagHelpers from Rails 3 back to Rails 2.3.x. So you can now use:


<%= f.email_field(:email) %>

<%= email_field_tag(:user, %>

All helpers are Rails 3 compliant so after updating to Rails 3 just remove the plugin.

Category: Ruby on Rails
Date: 2010-07-27 15:29

Rails will_paginate with acts_as_ferret

I wanted to use pagination in one of my Rails projects where I was also using the acts_as_ferret plugin. Now normally one would use


in the controller and in the view render with:

<%= will_paginate @collection %>

But with acts_as_ferret the controller will contain:

@collection=Model.find_with_ferret(params[:search], {:page=> params[:page], :per_page=>Model.per_page})

This is not a problem however. Acts_as_ferret is compatible with will_paginate. Your default will_paginate() helper will still be working.