简体   繁体   中英

Show Rails Console on all the pages

When I run into an error on a rails 5.0 app page while on development mode, I receive an error page with the rails web-console at the bottom of the page like in the screenshot below. The console seems to be pretty useful for running the methods of that controller in which the error occurred.

示例控制台

Is it possible to enable it on all the pages so I can access it without an error page?

On the web-console gem page , it says you can manually run the console in any page of your application. The docs says the following:

For example, calling console in a view will display a console in the current page in the context of the view binding.

 <% console %>

Calling console in a controller will result in a console in the context of the controller action:

class PostsController < ApplicationController
  def new
    console
    @post = Post.new
  end
end

The method is defined in Kernel and you can invoke it any application code.

Only one console invocation is allowed once per request. If you happen to have multiple ones, a WebConsole::DoubleRenderError will be raised.

Maybe this will help you call the console on the pages you want it to appear.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM