Could not open library ‘libgtkmm-2.4.so’: libgtkmm-2.4.so: cannot open shared object file: No such file or directory.

Problem

If you have setup guard with your Rails project and you are trying to run it in an (K)Ubuntu installation you get the following message:

Could not open library 'libgtkmm-2.4.so': libgtkmm-2.4.so: cannot open shared object file: No such file or directory.

Solution

Install the missing library with the following:

sudo apt-get install libgtkmm-2.4

Cucumber – Carrierwave – ImageUploader – Variable class

Problem
You would like to test the carrierwave imageuploader with a cucumber test, but you would also like to use a generic step that can be used with different classes and different image file column names.

Solution
Use the following and perhaps put it a file named features/common_steps.rb

Then /^the url for the column "([^"]*)" of model "([^"]*)" should be "([^"]*)"$/ do |col,mdl,url|
  # First get tne class name from the mdl argument by using the Kernel.const_get method
  m = Kernel.const_get(mdl).first
  # And then use the send with the column name (col) to call the model's field,
  # the url method of ImageUploader to get the full path
  # and basename to get only the file name
  File.basename(m.send(col).url).should == url
end

Changing local timezone in Debian server

Problem

You have developed your application in your local environment or you use it in an environment that has your local timezone, but your live deployment server is in a hosted server that has a different timezone. So a lot of the SQL queries, are not working correctly.

 

Solution

Login as root in your server and run:

dpkg-reconfigure tzdata

and then reload your database server.

setting dynamic event_source in jquery fullcalendar in rails application

Problem

You would like to use the fullcalendar jquery plugin to be able to display events in your rails application, but you also want to be able to set the eventSources dynamically depending on the path to your view, especially if your view contains a relationship as in the following example:

model_a/1/model_b (user/14/comments)

Solution

Change your eventSources to be something like the following and using the jQuery.ajaxSettings.url :

 // a future calendar might have many sources.
    eventSources: [{
      url: jQuery.ajaxSettings.url,
      color: 'orange',
      textColor: 'black',
      ignoreTimezone: false
    }],

 

ActiveSupport::TimeWithZone comparisons

Problem
You have two dates that you want to compare in your Rails application, which are both ActiveSupport::TimeWithZone.

Although they both look identical, when you are trying to compare them for equality (using ==), you get back false as a result.

 

Solution

These dates can have a difference in milliseconds that doesn’t normally get displayed. So first of all try to use to_f to see if they really have a difference.

If they do, then you would need to compare them by converting them to integers first as in :

date_a.to_i == date_b.to_i

and you should be getting back true

The user limit on the total number of inotify watches was reached or the kernel failed to allocate a needed resource. (Errno::ENOSPC)

Problem

When using the guard gem together with spork and cucumber and rspec to automate testing in your rails app, you get the following error:

The user limit on the total number of inotify watches was reached or the kernel failed to allocate a needed resource. (Errno::ENOSPC)

which also causes the guard to stop running.

Solution

Looking at the directory where the error takes place it appears there are a lot of temp files in the public/uploads/tmp directory that are not cleared up (using carrierwave for image uploading).
Maybe adding an initializer as suggested here would solve the clearing up of the files.
Otherwise by manually deleting the files and running guard again, it should work as expected.

Polymorphic associations’ as and where is used in SQL

Problem

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:

 

class Picture < ActiveRecord::Base
  belongs_to :imageable, :polymorphic => true
end

class Employee < ActiveRecord::Base
  has_many :pictures, :as => :imageable
end

class Product < ActiveRecord::Base
  has_many :pictures, :as => :imageable
end

Solution

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:

SELECT `images`.*
FROM `images`
WHERE (`ratings`.imageable_id = 289
      AND `images`.imageable_type = 'Product')