When a request asking for an action in a controller that does not exist in your application a not found error page is displayed. You can actually use routes to redirect this requests to the a default page.

Just add the following line the last rule in your config/routes.rb file:

map.connect ‘*path’, :controller => ‘main’, :action => ‘redirect_to_default’

Whenever a request asking for an action in a controller that you have not defined hits your application, rails will call the action ‘redirect_to_default’ in the ‘main’ controller (you can obviously change the controller and the action to fit your needs).

The code for the redirect_to_default action is a simple rails redirect:

def redirect_to_default
  redirect_to :action => 'index'
end

Advertisements

If you want to pass specific options like the table type and the charset to use when creating tabled though Rails migrations, pass an options parameter to the create_table method:

create_table :my_table, :options => 'ENGINE=InnoDB DEFAULT CHARSET=utf8', :force => true do |t|
t.column :column1, :string
t.column :column2, :string
end

In order to set a maintenance page in apache 2 you need:

  1. Enable mod_rewrite. In my debian server I just need to do the following:
    ln -s /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/rewrite.load
  2. Create the maintenance page somewhere in your disk server. I created it under /srv/www/maintenance
  3. Set up apache2 to redirect all requests to your site to the maintenance page (you will need to comment out the current apache2 directives for your website). In my case I have a /etc/apache2/sites-available/mysite file that is linked from /etc/apache2/sites-enabled/mysite.
    #Maintenance page
    <VirtualHost *:80>
    ServerName mysite.com
    ServerAdmin postmaster@mysite.com
    RewriteEngine on
    RewriteCond %{REQUEST_URI} !/index\.html$
    RewriteCond %{REQUEST_URI} !/logo\.gif$
    RewriteRule ^(.*)$ /index.html [L]
    DocumentRoot “/srv/www/maintenance”
    </VirtualHost>
  4. Reload apache2 configuration:
    /etc/init.d/apache2 reload

In my case I only have an index.html and a logo.gif file in the /srv/www/maintenance folder. If you have more files that are needed to render the maintenance page you will need to add some extra “RewriteCond %{REQUEST_URI} !/yourfile\.extension$” rules.

Note if you do not use the rewrite engine, the maintenance page will show up when you users access http://mysite.com or http://mysite.com/index.html, but if they access http://mysite.com/something_else they will get a nice “Page not found error”.

When one of the hard disks in a RAID 1 gets out of the RAID because it is no longer in sync with the other disk, you can easily resynchronize it with the following command:

raidhotadd /dev/mdX /dev/sdY

X and Y should be set to the appropriate values.

‘cat /proc/mdstat’ would tell you if your RAID system is healthy.

The configuration of your RAID is set in the file /etc/raidtab which will tell you the disks in the RAID and you can compare the results with the cat command above to see which disk is missing.

I use this script to verify if all disks in my RAID 1 are working fine:


#!/bin/bash
#Check if both drive are up
if [ `grep [UU] /proc/mdstat | wc -l` != 2 ] || [ `grep "2/2" /proc/mdstat | wc -l` != 2 ]; then
  cat /proc/mdstat
  exit 1
fi
exit 0

More info here.

If you want to a validation rule to be applied only when the corresponding attribute has a value, you can use the :allow_nil => true parameter. I don’t know if this works on any Rails model validation rule, but it might well be. The Rails documentation at http://api.rubyonrails.org/ is not very clear in that respect. For each validation rule it lists the parameters it accepts and for the validates_format rule the :allow_nil parameter was not listed. It is listed at the begining as a default parameter for all validation rules though.

In my case I wanted a column in the table to either be null or have a value that matched a particular regular expression, so I ended up with something like

validates_format_of       :email, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/, :message => ‘Invalid Email address’, :allow_nil => true