2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

rails/info/propertiesに項目を追加する

Posted at

Rails4ではdevelopment環境のサーバーにlocalhostから /rails/info/properties にアクセスすると以下のように Rails のバージョン等が表示できる。

Properties.png

Rails::Info.property を使ってこの項目を追加することができる: 例 config/initializers/expand_rails_info.rb をこの内容で書くと

Rails.application.config.after_initialize do
  Rails::Info.property "Database Version" do
    ActiveRecord::Base.connection.select_one("SELECT SQLITE_VERSION();").values.first
  end                                                                                                                                                                             
end

最後の部分が↓のようになる。

Properties 2.png

その他まつわる小ネタ

  • development 以外でも使いたいよ: get 'foo' => 'rails/info#properties' みたいに自分で routes に追加すれば使えるよ
  • localhost 以外でも使いたいよ: config.consider_all_requests_local を適切に運用
  • 他のControllerやViewの一部に使いたいよ: Rails::Info.to_html とか Rails::Info.to_s とかが使えるかも
2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?