Polymorphic associations’ as and where is used in SQL


You are using a polymorphic association in your application, and you would like to know how exactly the as declaration in your model has_many is used in the SQL by ActiveRecord. So following the example in the Rails Guides with the following models:



ActiveRecord uses the as in the model declaration as a guide to find the foreign id key in the polymorphic association, by adding the _id to the :as name. So following the
example above the query for the product would be:

Cucumber Table transformations with Factory Girl

After reading this post here, to be able to use the Cucumber table trasformatios feature to build objects in your cucumber tests, you would like to use FactoryGirl instead of the standard model.
The reason for using FactoryGirl could be that your model needs a few more attributes (mandatory fields), that you don’t want to specify in your cucumber table, but you want the factory to take care of them.

The only difference would take place in the transformation step.
So if you would originally have the following:

and for example your user has also fields like password, date of birth, that are mandatory in the model validations, you would put them in your factory define declaration like:

and replace the tranformation to:


The actual step would similar to the one in the blog article:

Secure Random passwords in Ruby

You would like to use a random password in ruby. Most solutions describe using the Digest library (Digest::SHA1).

According to the post here, you can achieve the same by using ActiveSupport’s secure_random library.
To use it in Ruby outside Rails use:

and inside rails:

passenger ArgumentError (invalid byte sequence in US-ASCII)

After upgrading your server to use rvm and Ruby 1.9 you get the following error when you are trying to access certain parts of your redmine installation:

passenger ArgumentError (invalid byte sequence in US-ASCII)

If you follow the instruction posted here, you can add the following to your redmine’s “RAILS_ROOT/config/initializers/string_encodings.rb”:

Encoding.default_external = 'UTF-8'

and restart your application

Passenger (mod_rails) gem installation – Apache2 – Debian – rvm

You would like to (re)-install passenger after a system wide rvm installation, but you only have the mod_passenger.c file and not the .so after the gem installation.

Make sure that after using gem install passenger you also use the command to install the apache2 passenger module:


you should then be able to see the .so file and add it to your /etc/apache2/mods-available/passenger.load

multiple user installation of rvm in Debian

You would like to install rvm as a multiple user installation in Debian.

You would need to do the following:

as root

  • bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)

for each individual user you want to use rvm

  • in the user’s .bashrc or .bashrc_profile add the following at the bottom:
    [[ -s "/usr/local/rvm/scripts/rvm" ]] && source "/usr/local/rvm/scripts/rvm" # This loads RVM into a shell session.
  • reload the .bashrc or .bashrc_profile by:
    source .bashrc|.bashrc_profile

and you should be able to do rvm -v.