Regular expression checking of landline/mobile UK numbers in Ruby on Rails

Problem
You want to have validations for phone numbers in Ruby on Rails code.

Solution
The mobile numbers in UK should start with a 0, followed by 7, then a number between 5 and 9, and finally another 8 numbers.
For the landline numbers in UK the number should start with 0, followed by either 1 and 8 or 9 digits, or by 2 or 3 and then 9 digits.
So in order to use a regular expression in your validations, you could use something like the following in your model:

case phone_no_type

  when 'mobile'

    if phone_no !~ /\A(([0][7][5-9])(\d{8}))\Z/

      errors.add('Mobile number")

    end

  when 'landline'

    if phone_no !~ /\A([0])((([1])(\d{8,9}))|(([2-3])(\d{9})))\Z/

      errors.add('Landline number')

    end

  end

Red Box progress indicator with active_scaffold_upload branch

Problem
You need to display a splash screen when uploading files to a Ruby on Rails application.

Solution
My model:

class Number < ActiveRecord::Base
  file_column :intro
  file_column :vmail
end

The steps I have followed.

  1. Install redbox plugin from project path run:
    ./script/plugin install svn://rubyforge.org/var/svn/ambroseplugins/redbox
  2. If files redbox.js, redbox.css and redbox_spinner.gif haven’t been copied over to the public folders copy them over manually or go to vendor/plugins/redbox and run:
    rake update_scripts
  3. Find an animated gif for the progress indicator to be used (ie pleasewait.gif) and copy it over to public/images.
  4. In order to be able to use the progress indicator in different parts of the application, add the following to the app/views/layouts/ :
    application.rhtml
                 <%= stylesheet_link_tag 'redbox' %>
                <%= javascript_include_tag 'redbox' %>

    near the place where <= javascript_include_tag :default > is located.
    Also at the bottom of the page create the content of the redbox:

    <p id="redbox" style="display: none"> </p>
    
    <p style="color: blue"> Please wait ....
    
    Uploading files
    
    <img src="/images/pleasewait.gif" width="200" />
    
  5. Copy _update_form.rhtml, update_form.rhtml and update.rjs from vendor/plugins/active_scaffold_upload/frontends/default/views/ to the app/views/numbers (model you want to use).
  6. To display the redbox in the numbers/_update_form.rhtml add the following in the submit_tag:
     , :onClick => "return RedBox.showInline('redbox') " %>
  7. To close the redbox after the uploading was successful, add the following in numbers/update.rjs as the first line inside controller.send :successful? clause:
    page.RedBox.close()