RailsMyAdmin を試してみた

MOONGIFTで知った,RailsMyAdminを試してみました。 現在ある仕事のプロトタイプをRailsで作っているのでこのようなプラグインは本当に助かります :-)

RailsMyAdminは http://www.moongift.jp/2007/07/railsmyadmin/ にあるように、プロジェクトで使っている全て、または指定したテーブル内のデータをリスト、変更、作成、削除が行えます(メンテナンス画面ですね)。


インストールは http://code.google.com/p/railsmyadmin/ にあるように script/plugin install でプラグインをインストールし script/generate my_admin で RailsMyAdmin 一式を作成します。

設定ですが、config/environment.rb に以下のようなコードを追加します。

## MY ADMIN CONFIG
require 'my_admin/my_admin_tool'

# If you only want certain models to be available to RailsMyAdmin,
# set :all_models to false and specify the desired models in MY_ADMIN_MODELS
MY_ADMIN_GLOBALS  = {:all_models => true, :confirm_destroy => false}

# Uncomment the following line if you set :all_models to false above.
#MY_ADMIN_MODELS = [User, Content]
# Replace [User, Content] with your desired array of model classes that
# RailsMyAdmin should be restricted to.

# MY_ADMIN_AUTH must define a Proc object that takes as a paramater
#   an ApplicationController instance variable (c - in the example below).
# If you have a method defined in your ApplicationController,
#   'admin_logged_in?' for example, the following sample code will
#    authenticate against that method and only allow visitors to
#    view RailsMyAdmin if the 'admin_logged_in?' method returns true.

MY_ADMIN_AUTH     = Proc.new { |c| c.send('admin_logged_in?') }

コメントにあるように、RailsMyAdmin ページのアクセス制限は MY_ADMIN_AUTH に定義された関数で行います。
今回は、プロトタイプなのでアクセス制限は不要で MY_ADMIN_AUTH = Proc.new { |c| true } としました。


また、spy というテーブル内容のリアルタイムモニターのような機能もありますが、この機能はテーブルに created_at カラムが無いとエラーになります ^^;