Rails – Mysql::Error: Got error 28 from storage engine

Problem
Trying to access your rails application in your development pc, you get the error:

Mysql::Error: Got error 28 from storage engine

in your console.

Solution
It turns out that this specific error is a MySQL error, indicating that you have run out of space in the partition that the MySQL server stores its files (/var/lib/mysql).
Looking at the folder there, you can see a very large file called ibdata1.
This file holds all the information about your InnoDB tables and transactions in your MySQL. According to other posts after a Google search, it seems that this file cannot be reduced in size either by removing/truncating your tables or deleting databases that you don’t need. There are quite a few solutions out there if you really need to keep a backup of your databases, but if you only using your database for development and you DON’T NEED (!!) your data or tables, you can move this big ibdata1 to another partition for backup and restart your mysql, that will create a new file.

Testing Active_Mailer with GMail in development

Problem
You want to test your email configuration and be able to send emails in your development environment, using a GMail account in a Rails application using 2.3.2.

Solution
Start your console in your development environment:

./script/console

Add the following replacing your GMail details:


ActionMailer::Base.smtp_settings = {
:enable_starttls_auto => true,
:address => "smtp.gmail.com",
:port => 587,
:domain => "your_gmail_domain",
:authentication => :plain,
:user_name => "your_gmail_user_name",
:password => "your_gmail_password"}

Add a simple email class:


class MyMailer < ActionMailer::Base def test_email @recipients = "an_address_to_sent_to@domain.com" @from = "address_from@your_google_domain.com" @subject = "test from dev console" @body = "this is the body" end end

and to finally test the email:


MyMailer::deliver_test_email

if it doesn't return with an error but with something like:


TMail::Mail port=#TMail::StringPort:id=0x..fdab4cee0 bodyport=#TMail::StringPort:id=0x..fdab4a9ec

then it should be working so add the configuration to your environments/development.rb

config.action_mailer.smtp_settings { ... }

God gem problem unpacking with Rails 2.3.2

Problem
When using the god gem in a Rails 2.3.2 application, when you unpack (freeze) the god gem with :

sudo rake gems:unpack

it creates the god drectory in vendor/gems with root owner, and group permissions.

Solution
Remember to change owner and group for the folder

sudo chown -R user_name vendor/gems/god-0.11.0
sudo chown -R user_name vendor/gems/god-0.11.0

406 Not Acceptable – Princely – Dreamhost

Problem
You get a ‘406 Not Acceptable’ response from the web server when you try to use the princely plugin for generating pdf on a Ruby on Rails application hosted on dreamhost.

Solution
Having tried the ‘Extra Web Security’ settings in dreamhost Web panel, and setting them on/off did not get very far.
Also setting up an .htaccess file didn’t seem to make any difference.
So the mod_security settings did not seem to be the cause of the problem.
Having a look at the apache error log files which in the case of the dreamhost ps are in /usr/local/dh/apache2/logs/apache2-ps_name it turns out that the problem was that the path for the prince binary was not setting up correctly in the file vendor/plugins/princely/lib/prince.rb on line 26.
A quick hack to make it work until finding the reason for the problem is to hardcode the path to the prince binary, so:
@exe_path = `which prince`.chomp
if @exe_path.nil?
@exe_path=’/usr/local/bin/prince’
end

NoMethodError: undefined method `timeout=’ for Geokit::Geocoders:Module

Problem
Using the latest version of Geokit gives the error for undefined method ‘timeout’. This could happen if the gem/plugin didn’t modify the config/environment.rb file, and you had to copy the configuration values from an older version.

Solution
The configuration variable has changed in the latest version (1.5.0) from timeout to request_timeout, so change it in your config/environment.rb file as :
GeoKit::Geocoders::request_timeout = 3

Pdf with .doc templates using prawn in Ruby on Rails

Problem
You want to generate pdf documents in your Ruby on Rails app using .doc templates.

Solution
Open the .doc document in OpenOffice and save it as an Open Document Format (.odt).

Open the saved .odt document and export to pdf, making sure you use ‘Losless compression’ in the General Options section.

Use imagemagick’s convert to make the pdf file to an image (setting the density to your requirements – default is 72dpi):

convert -density 150 one.pdf one.png

Copy the image one.png to your rails image directory (public/images).

Use the image as a background to the pdf created by prawnto (install plugin if you don’t have it) with:

templ=”#{RAILS_ROOT}/public/images/one.png”
pdf.image(templ, {:position => :center, :vposition => :top, :scale => 0.215})

Put the database field(s) text on position (you’ll have to play around with the coordinates to get it right), like:

pdf.font “#{Prawn::BASEDIR}/data/fonts/DejaVuSans.ttf”, :size => 9
pdf.text “#{@model_name.fielda_name}”, :at => [100,530]
pdf.text “#{@model_name.fieldb_name}”, :at => [100,510] …

RubyGem version error: rack(0.3.0 not ~> 1.0.0)

Problem
Trying to deploy in dreamhost with capistrano you get the error:

RubyGem version error: rack(0.3.0 not ~> 1.0.0)

Solution
Log in with ssh to your dreamhost account and then install the newer version of rack that is not yet installed in dreamhost:

gem install rack

That assumes that you have followed the instructions for setting up your local gems in dreamhost (here) and you already have a ~/username/.gems directory.

You may probably need to also add the following to your config/environment.rb :

ENV[‘GEM_PATH’] = ‘/home/USERNAME/.gems’

Note 09-Sep-2009
It seems that according to the dreamhost wiki we need to add the following to the config/environment.rb, instead of the line above:

if ENV[‘RAILS_ENV’] == ‘production’
ENV[‘GEM_PATH’] = ‘/home/USERNAME/.gems’
require ‘/home/USERNAME/.gems/gems/rack-1.0.0/lib/rack.rb’
end

to use the locally installed rack-1.0.0 gem, instead of the rack installed by dreamhost.

Mandriva – Eclipse – Aptana RadRails

Problem
You want to do a new installation of Aptana RadRails IDE in Mandriva as an eclipse plugin.

Solution

  • Install eclipse first (selecting openjdk when prompted):
    sudo urpmi eclipse
  • According to the instructions here take the following steps:
  • From the Help menu in Eclipse, select Software Updates
  • Select the Available Sotware tab
  • Click the “Add Site..” button.
  • Specify the Location Url update site: http://update.aptana.com/update/studio/3.4/ and click OK
  • Select the checkbox next to the added update site.
  • Click the install button.
  • Complete instruction to install from update site and restart eclipse
  • Go to ‘My Aptana’ page and then the ‘Plugins’ tab on the top
  • Click on Aptana Rad Rails ‘Get It’ link and get through the next sequence of screens select ‘ok’.
  • Restart Eclipse and RadRails should now be installed.