@thorikiriのてょりっき

@thorikiriの技術ネタや本を読んだブログです

RailsAdminとconcern modulesを共存させる

RailsAdminって便利ですね。管理が非常に楽になります。
RailsAdminを使っていたところに、concern modulesを組み込んでみました。
すると、今まで動いていたRailsAdminが動かなくなるという現象が発生しました。

RuntimeError in RailsAdmin::MainController#dashboard
Circular dependency detected while autoloading constant Concerns::Hogehoge

Extracted source (around line #6):
    previous_level = Rails.logger.level
    Rails.logger.level = Logger::ERROR if env['PATH_INFO'].index("/assets/") == 0
    call_without_quiet_assets(env).tap do
      Rails.logger.level = previous_level
    end
  end

Rails.root: /path/to/railsapp

Application Trace | Framework Trace | Full Trace
config/initializers/quiet_assets.rb:6:in `call_with_quiet_assets'
Request

ぐぐったら、こちらに行き着きました。
Circular dependency detected while autoloading constant · Issue #1697 · sferik/rails_admin · GitHub

config/initializers/rails_admin.rbに次の定義を行えば解決出来るとのことです。

# Include specific models (exclude the others):
Rails.application.eager_load!
config.included_models = ActiveRecord::Base.descendants.map!(&:name)

で、実際に解決しました。
RailsAdminではデータベースのテーブルの管理が出来るのですが、その対象をActiveRecordのクラスを見て設定しているようです。
app/modelsの中のファイルを見ているのですが、app/models/concernsの中身も見てしまいます。
そこで、ActiveRecordのサブクラスだけですよ。と指定しているんですね。
とりあえず解決してめでたしめでたしでした。

Windows7にRails4をインストールする

Windows7にRails4をインストールしてみます。
あらかじめRuby2がインストールされていることとします。
環境

Rails4 インストール

正式リリースされているので、gem install railsでインストール出来ると思ってましたが、次のようなエラーが出ました。

> gem install rails
ERROR:  Error installing rails:
        The 'atomic' native gem requires installed build tools.

Please update your PATH to include build tools or download the DevKit
from 'http://rubyinstaller.org/downloads' and follow the instructions
at 'http://github.com/oneclick/rubyinstaller/wiki/Development-Kit'

どうやら、DevelopmentKitが入っていないとダメなようですね。
なので、こちらからダウンロードします。
今回は、DevKit-mingw64-64-4.7.2-20130224-1432-sfx.exeをダウンロードしてみた。
ダウンロードしたら、exeファイルを実行する。ディレクトリを聞かれるので、保存するディレクトリを指定する。
展開したディレクトリで、次のコマンドを実行する

> ruby dk.rb init
[INFO] found RubyInstaller v2.0.0 at C:/ruby

Initialization complete! Please review and modify the auto-generated
'config.yml' file to ensure it contains the root directories to all
of the installed Rubies you want enhanced by the DevKit.

> ruby dk.rb install
[INFO] Updating convenience notice gem override for 'C:/ruby'
[INFO] Installing 'C:/ruby/lib/ruby/site_ruby/devkit.rb'

DevelopmentKitのインストールが出来たようです。それでは、再度Rails4のインストールをしてみましょう。

> gem install rails4
・・・
25 gems installed

インストールできたようですので、確認します。

> rails -v
Rails 4.0.0

オッケーのようですね。