passenger ArgumentError (invalid byte sequence in US-ASCII)

Problem
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)

Solution
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

Problem
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.

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

passenger-install-apache2-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

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

Solution
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.

Could not find generator jquery:install

Problem
When you try to replace prototype with jquery in your Rails 3.0.x application, by using the command described in the Agile Web development book:

rails generate jquery:install --ui --force

you get the following error:

Could not find generator jquery:install

Solution
You would need to follow the steps below:

  1. Add gem “jquery-rails”, “~> 1.0.13” in your Gemfile, and run bundle install
  2. run the command described above: rails generate jquery:install –ui –force

Now you should be able to see something like:

remove public/javascripts/prototype.js
remove public/javascripts/effects.js
remove public/javascripts/dragdrop.js
remove public/javascripts/controls.js
copying jQuery (1.6.2)
create public/javascripts/jquery.js
create public/javascripts/jquery.min.js
copying jQuery UI (1.8.14)
create public/javascripts/jquery-ui.js
create public/javascripts/jquery-ui.min.js
copying jQuery UJS adapter (cd619d)
remove public/javascripts/rails.js
create public/javascripts/jquery_ujs.js

Formatting edit field values in a Rails edit view

Problem
You have an edit form that displays a value in a format (ie dates) that you want to modify by using a helper method (ie display_datetime).

Solution
According to the suggestion here, you can use the following in your view:

<%= f.text_field :date_field_to_format, :value => display_datetime(f.object.date_field_to_format) %>

SL4Ar4 crashing after installation

Problem
After installing SL4A_r4 (Scripting Layer for Android), on your Android phone, and before installing any interpreters every time you start your SL4A app, it keeps crashing after a few seconds.

Solution
If you install an interpreter (ie JRuby), then the application stops crashing.
You would need to be quick to start the installation before the application crashes, by doing the following:

Settings -> View -> Interpreters -> Settings -> Add and then select the interpreter you would like.

/lib/libz.so.1: no version information available

Problem
You are following the steps described in the book ‘Hello, Android’, but when you try to change the interface in section 3.3 ‘Creating the Opening Screen’, and try to run the application in either the emulator or the phone you get the following error message in the eclipse console:
/lib/libz.so.1: no version information available...

Solution
You will need to make sure that you add the needed strings, i.e (main_title, continue_label, new_game_label, about_label and exit_label) in the Sudoku/values/strings.xml file, which is described in page 51, but is not clear that you have to do that before running the app. So your strings.xml file should look like:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Sudoku</string>
<string name="main_title">Android Sudoku</string>
<string name="continue_label">Continue</string>
<string name="new_game_label">New Game</string>
<string name="about_label">About</string>
<string name="exit_label">Exit</string>
</resources>

Testing associations in Rspec

Problem
You would like to test your model associations in an RSpec model spec, to make sure that they are correctly set up.

Solution
After some Google searching and coming across this article here, ended up using the second method described there with the reflect_on_association method, as it doesn’t need the inclusion of another gem.
So for example to to test multiple has_many or belongs_to associations in your model rspec you could use something like:
context "check associations" do
# belongs_to associations
%w{bel_to1 bel_to2}.each do |bt|
it "should belong to #{bt}" do
m = Model.reflect_on_association(:"#{bt}")
m.macro.should == :belongs_to
end
end
# has_many associations
%w{has_many1 has_many2 has_many3}.each do |hm|
it "should have many #{hm}" do
m = Model.reflect_on_association(:"#{hm}")
m.macro.should == :has_many
end
end
end

The single-table inheritance mechanism failed to locate the subclass:

Problem
You have correctly setup your Single Table Inheritance tables as in:

class Parent < ActieRecord::Base ; end class Child < Parent ; end

but everytime you are trying to use that in a cucumber feature, or in rails console you get the following error:

The single-table inheritance mechanism failed to locate the subclass: 'child'. This error is raised because the column 'type' is reserved for storing the class in case of inheritance. Please rename this column if you didn't intend it to be used for storing the inheritance class or overwrite Parent.inheritance_column to use another column for that information. (ActiveRecord::SubclassNotFound)

Solution
Make sure that when use the subclass name in a feature, or you create a record in the database the initial letter is in capital!
So make sure that in this case the type column contains 'Child' and not 'child'