Using ActiveScaffold in Rails 2.2 after using default scaffolding

Problem
You want to use ActiveScaffold in Rails 2.2, in a model that you have created using the standard Rails scaffolding script.

Solution

  1. Install the ActiveScaffold plugin:
    script/plugin install git://github.com/activescaffold/active_scaffold.git -r rails-2.2
  2. In your layout (model or application for all models) add the following:
    <%= javascript_include_tag :defaults %>
    <%= active_scaffold_includes %>
  3. In your controller file delete all the standard scaffolding code and add one line, so that your new controller should look like:
    class SomethingsController < ApplicationController
      active_scaffold :something
    end
  4. To configure a RESTful scaffold add the following to your route.rb file:
    map.resources :somethings, :active_scaffold => true
  5. Delete the views that were created from the standard rails scaffolding in the views/somethings folder (edit, show, index ...)
  6. Restart your server

You should now have an active scaffold for your model.

Comparing data from two big MySQL tables

Problem
You have two big tables in MySQL (>640K records), that maybe differ in the number of fields, but you want to make sure that the data in the common fields in both tables are the same.

Solution

  1. Use mysql to export the data from the first table in a csv file, selecting only the common fields.
    We use the /tmp folder on the server to make sure we have the right permissions to create the file:

    mysql>SELECT common_field1, common_field2, ... 
    INTO OUTFILE '/tmp/first_table.txt'
    FIELDS TERMINATED BY ','
    OPTIONALLY ENCLOSED BY '"'
    LINES TERMINATED BY '\n'
    FROM table1;
  2. If the tables are in different databases remember to switch db:
    use seconddb;

    Export the second table in the second file:

    mysql>SELECT common_field1, common_field2, ... 
    INTO OUTFILE '/tmp/second_table.txt'
    FIELDS TERMINATED BY ','
    OPTIONALLY ENCLOSED BY '"'
    LINES TERMINATED BY '\n'
    FROM table2;
  3. now use the diff. You can use any of the following options:
    • diff -q first_table.txt second_table.txt
    • diff first_table.txt second_table.txt > diff.txt