システム設定の覚え書き(3)

いくつかの設定ファイルを記述する(変更点のみ記述)

config/database.yml

データベースの設定ファイル.データベースは PostgreSQL を使う

development:
  adapter: postgresql
  encoding: unicode
  database: hogehoge_development
  pool: 5
  username: ユーザ名
  password: パスワード
  host: ホスト名
  port: 5432

test:
  adapter: postgresql
  encoding: unicode
  database: hogehoge_test
  pool: 5
  username: ユーザ名
  password: パスワード
  host: ホスト名
  port: 5432

config/ldap.yml

LDAP 認証の設定ファイル.database.yml とほぼ書式は一緒.ここでは省略

config/application.rb

従来 config/environment.rb に書かれていた内容はこちらに移動した.主にアプリケーションの設定を記述.参考にしたページは以下の通り

# vim:set fileencoding=utf-8 filetype=ruby:
require File.expand_path('../boot', __FILE__)

require 'rails/all'
require 'openssl'

# Bundler の設定
Bundler.require(:default, Rails.env) if defined?(Bundler)

# Haml setting
# デフォルトで escape_html にする ( XSS 対策)
Haml::Template.options[:escape_html] = true
# テンプレートを HTML5 にする
Haml::Template.options[:format] = :html5

# 出力のデフォルトを UTF_8 にする
Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_8

# Ruby 3.0 ではシステム名のモジュールができる
module Hogehoge
  class Application < Rails::Application
    # autoload lib/*.rb
    config.autoload_paths += Dir["#{config.root}/lib/**/"]

    # タイムゾーンを東京に
    config.time_zone = 'Tokyo'

    # JavaScript files you want as :defaults (application.js is always included).
    config.action_view.javascript_expansions[:defaults] = %w()

    # デフォルトエンコードを utf-8 にする(Ruby 1.9用)
    config.encoding = "utf-8"

    # password フィールドを log に残さないようにする
    config.filter_parameters += [:password]

    # ログをカラーで出力しない
    config.colorize_logging = false

    ### Part of a Spork hack. See http://bit.ly/arY19y
    # 後日説明する spork を実行する際の自動的に読み込みの設定
    if Rails.env.test?
      initializer :after => :initialize_dependency_mechanism do
        # Work around initializer in railties/lib/rails/application/bootstrap.rb
        ActiveSupport::Dependencies.mechanism = :load
      end
    end
  end

  # rake db:seed の時に使うテーブル名
  CopyTables = %w(years gakunens campuses (以下続くが省略)
  )

  # その他,いくつかの設定は省略
end

config/initializers/inflections.rb

単数形・複数形の対応テーブル

ActiveSupport::Inflector.inflections do |inflect|
  inflect.irregular("campus", "campuses")
  inflect.irregular("syllabus", "syllabuses")
end

config/initializers/mime_types.rb

mime_type の設定.Excel と PDF を登録

Mime::Type.register "application/vnd.ms-excel; charset=utf-8", :xls
Mime::Type.register "application/pdf", :pdf

P.S.
設定ファイルで修正したものはこんなものだっただろうか.Evernote の自分用の覚え書きと違って,一部匿名でかかないといけないのが面倒だな(汗).inflections.rb あたりから何を作っているかは,バレバレな気もするが…….取り急ぎ設定関係の覚え書きは終了.明日から,いろいろと個々に工夫した点を書いていきます.まずは autotest の完全自動化かな.