Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
76e37e6f
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
76e37e6f
编写于
3月 02, 2015
作者:
R
Robin Dupret
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #19097 from gsamokovarov/web-console-guide
Web Console documentation for the upcoming 2.1 release [ci skip]
上级
ec8d8040
f46b1981
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
58 addition
and
49 deletion
+58
-49
guides/source/debugging_rails_applications.md
guides/source/debugging_rails_applications.md
+58
-49
未找到文件。
guides/source/debugging_rails_applications.md
浏览文件 @
76e37e6f
...
...
@@ -242,55 +242,6 @@ The contents of the block, and therefore the string interpolation, is only
evaluated if debug is enabled. This performance savings is only really
noticeable with large amounts of logging, but it's a good practice to employ.
Debugging with the `web-console` gem
-------------------------------------
The web console allows you to start an interactive Ruby session in your browser.
An interactive console is launched automatically in case of an error but can also
be launched for debugging purposes by invoking
`console`
in a view or controller.
For example in a view:
```
ruby
# new.html.erb
<
%= console %>
```
Or in a controller:
```
ruby
# posts_controller.rb
class
PostsController
<
ApplicationController
def
new
console
@post
=
Post
.
new
end
end
```
### config.web_console.whitelisted_ips
By default the web console can only be accessed from localhost.
`config.web_console.whitelisted_ips`
lets you control which IPs have access to
the console.
For example, to allow access from both localhost and 192.168.0.100, you can put
inside your configuration file:
```
ruby
config
.
web_console
.
whitelisted_ips
=
%w( 127.0.0.1 192.168.0.100 )
```
Or to allow access from an entire network:
```
ruby
config
.
web_console
.
whitelisted_ips
=
%w( 127.0.0.1 192.168.0.0/16 )
```
The web console is a powerful tool so be careful when you give access to an IP.
Debugging with the `byebug` gem
---------------------------------
...
...
@@ -849,6 +800,63 @@ set forcestep
set
listsize 25
```
Debugging with the `web-console` gem
------------------------------------
Web Console is a bit like
`byebug`
, but it runs in the browser. In any page you
are developing, you can request a console in the context of a view or a
controller. The console would be rendered next to your HTML content.
### Console
Inside any controller action or view, you can then invoke the console by
calling the
`console`
method.
For example, in a controller:
```
ruby
class
PostController
<
ApplicationController
def
new
console
@post
=
Post
.
new
end
end
```
Or in a view:
```
html+erb
<% console %>
<h2>New Post</h2>
```
This will render a console inside your view. You don't need to care about the
location of the
`console`
call; it won't be rendered on the spot of its
invocation but next to your HTML content.
The console executes pure Ruby code. You can define and instantiate
custom classes, create new models and inspect variables.
NOTE: Only one console can be rendered per request. Otherwise
`web-console`
will raise an error on the second
`console`
invocation.
### Inspecting Variables
You can invoke
`instance_variables`
to list all the instance variables
available in your context. If you want to list all the local variables, you can
do that with
`local_variables`
.
### Settings
*
`config.web_console.whitelisted_ips`
: Authorized list of IPv4 or IPv6
addresses and networks (defaults:
`127.0.0.1/8, ::1`
).
*
`config.web_console.whiny_requests`
: Log a message when a console rendering
is prevented (defaults:
`true`
).
Since
`web-console`
evaluates plain Ruby code remotely on the server, don't try
to use it in production.
Debugging Memory Leaks
----------------------
...
...
@@ -905,6 +913,7 @@ References
*
[
ruby-debug Homepage
](
http://bashdb.sourceforge.net/ruby-debug/home-page.html
)
*
[
debugger Homepage
](
https://github.com/cldwalker/debugger
)
*
[
byebug Homepage
](
https://github.com/deivid-rodriguez/byebug
)
*
[
web-console Homepage
](
https://github.com/rails/web-console
)
*
[
Article: Debugging a Rails application with ruby-debug
](
http://www.sitepoint.com/debug-rails-app-ruby-debug/
)
*
[
Ryan Bates' debugging ruby (revised) screencast
](
http://railscasts.com/episodes/54-debugging-ruby-revised
)
*
[
Ryan Bates' stack trace screencast
](
http://railscasts.com/episodes/24-the-stack-trace
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录