新手问题 问个 Rails 里边用 pry 的问题

bwlinux · February 26, 2016 · Last by bwlinux replied at February 27, 2016 · 1816 hits

现在想调试 rails 程序,安装了 pry,pry-rails,pry-debugger。在 rails-root 下,运行 rails c,进入 pry 的 REPL,常见的命令都后,就是一直没有搞明白怎么在 pry 运行在 Helper 里边的 methods,比如在 app/helpers/tests_helper.rb 里边定义了一个 method:

module TestsHelper
def foo_bar
    puts 'Hello world!'
end
end

在 pry 的 REPL 里边,怎么运行这个 method,直接运行 foo_bar 不行,TestHelper.foo_bar 也不行。 外事求 Google,运气不好,没有找到答案。在 Pry 里边运行这个 foo_bar 方法的正确姿势是什么?谢谢。

在 pry 中执行

helper.foo_bar

也可以 include 这个模块

非常感谢,管用。 追加一个问题,在 pry 下,如果是在 app/services 下的文件里边的 method 呢?用 require?还是有其它直接的使用方法?

You need to Sign in before reply, if you don't have an account, please Sign up first.