Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

Sample console

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

like image 952
Suthan Bala Avatar asked Sep 08 '25 16:09

Suthan Bala


1 Answers

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.

like image 92
alessandrocb Avatar answered Sep 10 '25 07:09

alessandrocb