Ruby On RailsにLoginEngineの設定をしました

INDEX PAGE

Ruby On RailsにLoginEngineの設定をしました



書籍やWebのページにはRuby On Rails1.2系の設定例が多かったのですが
Ruby On Rails2.0系ではこの方法ではまったく動きませんでした。

/config/environment.rb
を編集するのは一緒なのですが、1.2系では下記サイトのように設定するらしいのですが
 http://uyota.asablo.jp/blog/2006/09/30/542977
2.0系では、下記のように書きました。

# Be sure to restart your server when you modify this file
##文字コードの設定
$KCODE = 'u'

# Uncomment below to force Rails into production mode when
# you don't control web/app server and can't set it the proper way
# ENV['RAILS_ENV'] ||= 'production'

# Specifies gem version of Rails to use when vendor/rails is not present

RAILS_GEM_VERSION = '2.0.2' unless defined? RAILS_GEM_VERSION

# Bootstrap the Rails environment, frameworks, and default configuration
require File.join(File.dirname(__FILE__), 'boot')

##LoginEngineの為の追加
require File.join(RAILS_ROOT, "vendor", "plugins", "engines", "lib", "engines", "deprecated_config_support")
require File.join(File.dirname(__FILE__), '../vendor/plugins/engines/boot')

Rails::Initializer.run do |config|
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# See Rails::Configuration for more options.

# Skip frameworks you're not going to use (only works if using vendor/rails).
# To use Rails without a database, you must remove the Active Record framework
# config.frameworks -= [ :active_record, :active_resource, :action_mailer ]

# Only load the plugins named here, in the order given. By default, all plugins
# in vendor/plugins are loaded in alphabetical order.
# :all can be used as a placeholder for all plugins not explicitly named
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]

# Add additional load paths for your own custom dirs
# config.load_paths += %W( #{RAILS_ROOT}/extras )

 ##LoginEngineの為の追加
 config.plugins = [ :engines, :all ]

# Force all environments to use the same logger level
# (by default production uses :info, the others :debug)
# config.log_level = :debug

# Your secret key for verifying cookie session data integrity.
# If you change this key, all old sessions will become invalid!
# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attacks.

config.action_controller.session = {
:session_key => '_makename_session',
:secret => '76c07c474ae7421e0c8f8a926d26bc015b4c678b1131af9da67667e6d5596b91175646a3fc9afcd3167940173e4586c35939ba4eb9980038a334d00215f2461f'
}

# Use the database for sessions instead of the cookie-based default,
# which shouldn't be used to store highly confidential information
# (create the session table with 'rake db:sessions:create')
# config.action_controller.session_store = :active_record_store

# Use SQL instead of Active Record's schema dumper when creating the test database.
# This is necessary if your schema can't be completely dumped by the schema dumper,
# like if you have constraints or database-specific column types
# config.active_record.schema_format = :sql

# Activate observers that should always be running
# config.active_record.observers = :cacher, :garbage_collector

# Make Active Record use UTC-base instead of local time
# config.active_record.default_timezone = :utc
end

##LoginEngineの為の追加
module LoginEngine
config :salt, "your-salt-here"
config :use_email_notification, false
config :user_table, "users"
end

※太字の所が追記箇所です。

さて、これで準備完了と思いWebサーバを起動したのですがサーバが起動しない(T_T)
エラーログも何を言っているのか良くわからないし途方にくれていたのですが
どうやらconfigの読み込みをつかさどる
/(RAILS_ROOT)/vendor/plugins/engines/lib/engines/deprecated_config_support.rb
が存在しないことが問題のようでした。
(Engine2.0系ではconfig読み込みを推奨していないらしくこのファイルが存在しないようです。)

というわけで、必至にネットで探してこのソースを発見しました。


/(RAILS_ROOT)/vendor/plugins/engines/lib/engines/deprecated_config_support.rb

class ::Module
# Defines a constant within a module/class ONLY if that constant does
# not already exist.
#
# This can be used to implement defaults in plugins/engines/libraries, e.g.
# if a plugin module exists:
# module MyPlugin
# default_constant :MyDefault, "the_default_value"
# end
#
# then developers can override this default by defining that constant at
# some point *before* the module/plugin gets loaded (such as environment.rb)
def default_constant(name, value)
if !(name.is_a?(String) or name.is_a?(Symbol))
raise "Cannot use a #{name.class.name} ['#{name}'] object as a constant name"
end
if !self.const_defined?(name)
self.class_eval("#{name} = #{value.inspect}")
end
end

# A mechanism for defining configuration of Modules. With this
# mechanism, default values for configuration can be provided within shareable
# code, and the end user can customise the configuration without having to
# provide all values.
#
# Example:
#
# module MyModule
# config :param_one, "some value"
# config :param_two, 12345
# end
#
# Those values can now be accessed by the following method
#
# MyModule.config :param_one
# => "some value"
# MyModule.config :param_two
# => 12345
#
# ... or, if you have overrriden the method 'config'
#
# MyModule::CONFIG[:param_one]
# => "some value"
# MyModule::CONFIG[:param_two]
# => 12345
#
# Once a value is stored in the configuration, it will not be altered
# by subsequent assignments, unless a special flag is given:
#
# (later on in your code, most likely in another file)
# module MyModule
# config :param_one, "another value"
# config :param_two, 98765, :force
# end
#
# The configuration is now:
#
# MyModule.config :param_one
# => "some value" # not changed
# MyModule.config :param_two
# => 98765
#
# Configuration values can also be given as a Hash:
#
# MyModule.config :param1 => 'value1', :param2 => 'value2'
#
# Setting of these values can also be forced:
#
# MyModule.config :param1 => 'value3', :param2 => 'value4', :force => true
#
# A value of anything other than false or nil given for the :force key will
# result in the new values *always* being set.
def config(*args)

raise "config expects at least one argument" if args.empty?

# extract the arguments
if args[0].is_a?(Hash)
override = args[0][:force]
args[0].delete(:force)
args[0].each { |key, value| _handle_config(key, value, override)}
else
_handle_config(*args)
end
end

private
# Actually set the config values
def _handle_config(name, value=nil, override=false)
if !self.const_defined?("CONFIG")
self.class_eval("CONFIG = {}")
end

if value != nil
if override or self::CONFIG[name] == nil
self::CONFIG[name] = value
end
else
# if we pass an array of config keys to config(),
# get the array of values back
if name.is_a? Array
name.map { |c| self::CONFIG[c] }
else
self::CONFIG[name]
end
end
end
end

このファイルを手動で作成することで何とかWebサーバが起動しました。
Railsってなんだかバージョン管理が適当だ(×_×)

続いて、DBの設定とアプリケーションの設定があるのですがそれは次のページで。


########################################################
◎LoginEngineの導入
 其の壱 http://d.hatena.ne.jp/sai-ou89/20080401
 其の弐 http://d.hatena.ne.jp/sai-ou89/20080402
 其の参 http://d.hatena.ne.jp/sai-ou89/20080403
 其の四 http://d.hatena.ne.jp/sai-ou89/20080404
 其の五 http://d.hatena.ne.jp/sai-ou89/20080604
########################################################

INDEX PAGE