LoginSignup
39

More than 5 years have passed since last update.

web-console を使えば Rails App のデバックが楽になる

Posted at

web-console

View 内でコンソールを立ち上げて、変数や parameter などの状態を見る事の出来るデバック用のライブラリ。
Rails 4.2 から デフォルトで入っていたんですね。こんな便利なデバッグツールを知らなかったなんて、損してた。。。

使い方

console を立ち上げたい View または、Controller で console メソッドを呼び出す

view
<% console %>
<p id="notice"><%= notice %></p>

<h1>Listing Users</h1>
...
controller
class UsersController < ApplicationController
  before_action :set_user, only: [:show, :edit, :update, :destroy]

  # GET /users
  # GET /users.json
  def index
    console
    @users = User.all
  end

...

これだけで、以下のようなコンソールが立ち上がります!

image

あとは、Rails Console と同じように、見たい情報を入力するだけ!

image

便利だ!

ちなみに、エラーページでは何も設定しなくても自動で立ち上がるようになります。変数の値とか見たいだけなら pry なんて埋め込む必要なかったんですねー。

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
39