Rails: user_engine の試用2006年11月14日 11時33分39秒

user_engine を設定する上での覚書。user_engine を使うためのプラグインをインストール。

% rails test
% cd test
% ruby script/plugin install engines
+ ./engines/tasks/deprecated_engines.rake
+ ./engines/tasks/engines.rake
+ ./engines/test/action_view_extensions_test.rb
+ ./engines/test/ruby_extensions_test.rb
% ruby script/plugin install login_engine
+ ./login_engine/test/mocks/mail.rb
+ ./login_engine/test/mocks/time.rb
+ ./login_engine/test/test_helper.rb
+ ./login_engine/test/unit/user_test.rb
% ruby script/plugin install user_engine
+ ./user_engine/README
+ ./user_engine/app/controllers/permission_controller.rb
+ ./user_engine/app/controllers/role_controller.rb

user_engine を使うための設定。いくつかのファイルは編集が必要。メールでの通知は一時停止した。config/environment.rb は末尾に以下を追加。

% cat >> config/environment.rb
module LoginEngine
  config :salt, "your-salt-here"
  config :user_email_notification, false

Engines.start :login
Engines.start :user

更にいくつかの変更。app/controllers/application.rb と app/helpers/application_helper.rb はほとんど空だった。

% cat > app/controllers/application.rb
# Filters added to this controller will be run for all controllers in the applic
# Likewise, all the methods added will be available for all controllers.

require 'login_engine'

class ApplicationController < ActionController::Base
  include LoginEngine
  include userEngine
  helper :user
  model :user
  #before_filter :login_required
  before_filter :authorize_action
% cat > app/helpers/application_helper.rb
# Methods added to this helper will be available to all templates in the applica
module ApplicationHelper
  include LoginEngine
  include UserEngine

config/environment.rb に管理者の設定を追加。

% vi config/environment.rb
module UserEngine
   config :admin_login, "the login name for your administrator user"
   config :admin_email, "an email address for your administrator"
   config :admin_password, "your initial admin password"

データベースを作成。ここでテーブルに必要事項が追加される。デフォルトでは users で、テーブルは空でなければいけないそうだ。

% rake db:migrate:engines:user_engine
(in /export/home/uyota/test)
Migrating engine 'user_engine'
== InitialSchema: migrating ===================================================
-- create_table("permissions", {:force=>true})
   -> 1.0751s
-- create_table("permissions_roles", {:force=>true, :id=>false})
   -> 0.0948s
-- create_table("users_roles", {:force=>true, :id=>false})
   -> 0.0210s
-- create_table("roles", {:force=>true})
   -> 0.0723s
== InitialSchema: migrated (1.2719s) ==========================================

== AddedOmnipotentFlagToRoles: migrating ======================================
-- add_column(:roles, :omnipotent, :boolean, {:null=>false, :default=>false})
   -> 0.9985s
Couldn't find the admin role.
If this is not a migration or test, your authorization data may be corrupt.
== AddedOmnipotentFlagToRoles: migrated (1.1167s) =============================

== AddedSystemRoles: migrating ================================================
-- add_column(:roles, :system_role, :boolean, {:null=>false, :default=>false})
   -> 0.0440s
== AddedSystemRoles: migrated (0.0519s) =======================================
% rake bootstrap
(in /export/home/uyota/test)
Creating guest role 'Guest'
Creating admin role 'Admin'
Creating user role 'User'
Creating admin user 'uyota'

script/server で起動し http://localhost:3000/user/login にアクセス。成功していれば、ログイン画面が出てくる。