Top Related Projects
Ruby on Rails
Quick Overview
The rails/web-console
project is a Ruby on Rails gem that provides a web-based console for debugging and inspecting your Rails application during development. It allows developers to interact with their application's code and state directly from the browser, making it a valuable tool for troubleshooting and understanding application behavior.
Pros
- Interactive Console: The web-console provides an interactive Ruby console that allows developers to execute code and inspect the application's state directly from the browser.
- Easy Integration: The gem is designed to integrate seamlessly with the Rails framework, making it easy to set up and use in any Rails project.
- Improved Debugging: The web-console can help developers quickly identify and resolve issues by providing a more accessible and user-friendly debugging experience.
- Collaborative Debugging: The web-console can be used to share the application's state with other developers, enabling collaborative debugging sessions.
Cons
- Security Concerns: The web-console provides direct access to the application's code and state, which can pose a security risk if not properly configured or used in a production environment.
- Performance Impact: The web-console may have a slight performance impact on the application, especially in high-traffic scenarios, as it adds additional processing and communication overhead.
- Limited Functionality: While the web-console is a powerful tool, it may not provide the same level of functionality as a full-featured debugger or development environment.
- Dependency on Rails: The web-console is tightly coupled with the Rails framework, which means it may not be suitable for use in non-Rails applications.
Code Examples
Not applicable, as this is not a code library.
Getting Started
Not applicable, as this is not a code library.
Competitor Comparisons
Ruby on Rails
Pros of rails/rails
- Comprehensive framework for building web applications, providing a wide range of features and functionality.
- Extensive community support and a large ecosystem of plugins and libraries.
- Robust and well-documented, making it easier for developers to get started and build complex applications.
Cons of rails/rails
- Can be more complex and have a steeper learning curve compared to smaller, more focused libraries like rails/web-console.
- May have a larger footprint and resource requirements, which can be a concern for smaller or more resource-constrained projects.
Code Comparison
rails/rails:
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
before_action :authenticate_user!
private
def authenticate_user!
redirect_to new_user_session_path unless user_signed_in?
end
def user_signed_in?
current_user.present?
end
def current_user
@current_user ||= User.find_by(id: session[:user_id])
end
end
rails/web-console:
module WebConsole
class Middleware
def initialize(app)
@app = app
end
def call(env)
if WebConsole.enabled? && WebConsole.request_local?(env)
WebConsole::Session.new(@app, env).render
else
@app.call(env)
end
end
end
end
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Current version: 4.2.1 | Documentation for: v1.0.4 v2.2.1 v3.7.0
Web Console
Web Console is a debugging tool for your Ruby on Rails applications.
Installation
Add the following to your Gemfile
:
group :development do
gem 'web-console'
end
Usage
The web console allows you to create an interactive Ruby session in your browser. Those sessions are launched automatically in case of an error and can also be launched manually in any page.
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 per request is allowed. If you happen to
have multiple ones, WebConsole::DoubleRenderError
will be raised.
Configuration
Web Console allows you to execute arbitrary code on the server. Therefore, be very careful who you give access to.
config.web_console.permissions
By default, only requests coming from IPv4 and IPv6 localhosts are allowed.
config.web_console.permissions
lets you control which IP's have access to
the console.
You can allow single IP's or whole networks. Say you want to share your
console with 192.168.0.100
:
class Application < Rails::Application
config.web_console.permissions = '192.168.0.100'
end
If you want to allow the whole private network:
Rails.application.configure do
config.web_console.permissions = '192.168.0.0/16'
end
Take a note that IPv4 and IPv6 localhosts are always allowed. This wasn't the case in 2.0.
config.web_console.whiny_requests
When a console cannot be shown for a given IP address or content type, messages such as the following is printed in the server logs:
Cannot render console from 192.168.1.133! Allowed networks: 127.0.0.0/127.255.255.255, ::1
If you don't want to see this message anymore, set this option to false
:
Rails.application.configure do
config.web_console.whiny_requests = false
end
config.web_console.template_paths
If you want to style the console yourself, then you can place style.css
at a
directory pointed by config.web_console.template_paths
:
Rails.application.configure do
config.web_console.template_paths = 'app/views/web_console'
end
You may want to check the templates folder at the source tree for the files you may override.
config.web_console.mount_point
Usually the middleware of Web Console is mounted at /__web_console
.
If there is a need to change the path, then you can specify it by
config.web_console.mount_point
:
Rails.application.configure do
config.web_console.mount_point = '/path/to/web_console'
end
FAQ
Where did /console go?
The remote terminal emulator was extracted in its own gem which is no longer bundled with Web Console.
If you miss this feature, check out rvt.
Why do I constantly get unavailable session errors?
All of Web Console sessions are stored in memory. If you happen to run on a multi-process server (like Unicorn), you may encounter unavailable session errors while the server is still running. This is because a request may hit a different worker (process) that doesn't have the desired session in memory. To avoid that, if you use such servers in development, configure them so they serve requests only out of one process.
Passenger
Enable sticky sessions for Passenger on Nginx or Passenger on Apache to prevent unavailable session errors.
How to inspect local and instance variables?
The interactive console executes Ruby code. Invoking instance_variables
and
local_variables
will give you what you want.
Why does the console only appear on error pages but not when I call it?
This can be happening if you are using Rack::Deflater
. Be sure that
WebConsole::Middleware
is used after Rack::Deflater
. The easiest way to do
this is to insert Rack::Deflater
as early as possible
Rails.application.configure do
config.middleware.insert(0, Rack::Deflater)
end
Why am I getting an undefined method web_console
?
Make sure your configuration lives in config/environments/development.rb
.
Credits
- Shoutout to Hailey Somerville for better_errors.
- Kudos to John Mair for binding_of_caller and debug_inspector.
- Thanks to Charles Oliver Nutter for all the JRuby feedback.
- Hugs and kisses to all of our contributors!
Top Related Projects
Ruby on Rails
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot