我正在研究不同的优化技术,我发现这篇文章分析效率代码?有人认为对调用堆栈进行采样比使用分析器更有效.基本思想是,如果您查看调用堆栈,您会看到应用程序最有可能花费大部分时间的位置,然后在那里进行优化.
这当然很有趣,他显然是这方面的专家,但我不知道如何在ruby中查看调用堆栈.在调试器中,我可以说"信息堆栈",但似乎只显示一行.
编辑:我看到Mike Dunlavey的评论:"我只想指出,如果你在调试器下运行,手动中断它,并显示调用堆栈......"
我只是不确定如何手动中断它并调整调用堆栈.
我正在使用Active Admin为某些模型提供管理员.我需要为其中一个提供自定义的新表单,但将编辑表单保留为Active Admin提供的默认表单.这就是我所拥有的.它的工作原理是它给了我想要的新表单,但编辑表单也使用了新表单,这不是我想要的:
ActiveAdmin.register Document do
form :partial => 'form'
end
Run Code Online (Sandbox Code Playgroud)
我试过这个,但它给出了一个错误,'new'是一个未定义的方法:
ActiveAdmin.register Document do
new do
form :partial => 'form'
end
end
Run Code Online (Sandbox Code Playgroud) 在RSpec中,it_behaves_like和之间有什么区别include_examples?
该文件说:
include_examples- 包括当前背景下的示例
it_behaves_like "name"- 在嵌套上下文中包含示例
但这究竟意味着什么呢?将一个替换为另一个似乎对我的测试是通过还是失败没有影响.在某些情况下,是否有理由偏爱另一个?
另外,是it_should_behave_like和it_behaves_like刚才的同义词?
我有一个控制器"UserController",应该响应正常和ajax请求http://localhost:3000/user/3.
当它是正常请求时,我想渲染我的视图.当它是一个AJAX请求时,我想返回JSON.
正确的方法似乎是一个respond_to do |format|障碍.编写JSON很简单,但是如何让它响应HTML并像往常一样呈现视图?
def show
@user = User.find(params[:id])
respond_to do |format|
format.html {
render :show ????this seems unnecessary. Can it be eliminated???
}
format.json {
render json: @user
}
end
end
Run Code Online (Sandbox Code Playgroud) 不确定这是否是Capybara问题,但我刚刚安装了Rails(4.1.1)和Rspec Rails(3.0.1),我想使用Capybara(2.3.0),但从未使用它我'遇到问题.我在spec/features中创建了一个"spec",规范本身按预期运行并传递,但是当运行rspec时,我得到以下"警告".有任何想法吗?我只需要在红宝石级别禁用警告吗?
/Users/typeoneerror/.rvm/gems/ruby-2.1.2@doki/gems/mail-2.5.4/lib/mail/network/delivery_methods/sendmail.rb:53: warning: shadowing outer local variable - to
/Users/typeoneerror/.rvm/gems/ruby-2.1.2@doki/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247: warning: loading in progress, circular require considered harmful - /Users/typeoneerror/.rvm/gems/ruby-2.1.2@doki/gems/capybara-2.3.0/lib/capybara.rb
from /Users/typeoneerror/.rvm/gems/ruby-2.1.2@doki/bin/ruby_executable_hooks:15:in `<main>'
from /Users/typeoneerror/.rvm/gems/ruby-2.1.2@doki/bin/ruby_executable_hooks:15:in `eval'
from /Users/typeoneerror/.rvm/gems/ruby-2.1.2@doki/bin/rspec:23:in `<main>'
from /Users/typeoneerror/.rvm/gems/ruby-2.1.2@doki/bin/rspec:23:in `load'
from /Users/typeoneerror/.rvm/gems/ruby-2.1.2@doki/gems/rspec-core-3.0.0/exe/rspec:4:in `<top (required)>'
from /Users/typeoneerror/.rvm/gems/ruby-2.1.2@doki/gems/rspec-core-3.0.0/lib/rspec/core/runner.rb:38:in `invoke'
from /Users/typeoneerror/.rvm/gems/ruby-2.1.2@doki/gems/rspec-core-3.0.0/lib/rspec/core/runner.rb:70:in `run'
from /Users/typeoneerror/.rvm/gems/ruby-2.1.2@doki/gems/rspec-core-3.0.0/lib/rspec/core/runner.rb:85:in `run'
from /Users/typeoneerror/.rvm/gems/ruby-2.1.2@doki/gems/rspec-core-3.0.0/lib/rspec/core/runner.rb:97:in `setup'
from /Users/typeoneerror/.rvm/gems/ruby-2.1.2@doki/gems/rspec-core-3.0.0/lib/rspec/core/configuration.rb:1051:in `load_spec_files'
from /Users/typeoneerror/.rvm/gems/ruby-2.1.2@doki/gems/rspec-core-3.0.0/lib/rspec/core/configuration.rb:1051:in `each'
from /Users/typeoneerror/.rvm/gems/ruby-2.1.2@doki/gems/rspec-core-3.0.0/lib/rspec/core/configuration.rb:1051:in `block in load_spec_files'
from /Users/typeoneerror/.rvm/gems/ruby-2.1.2@doki/gems/rspec-core-3.0.0/lib/rspec/core/configuration.rb:1051:in `load'
from /Users/typeoneerror/Dev/Doki/engines/doki_core/spec/features/accounts/sign_up_spec.rb:1:in `<top (required)>'
from /Users/typeoneerror/Dev/Doki/engines/doki_core/spec/features/accounts/sign_up_spec.rb:1:in `require'
from /Users/typeoneerror/Dev/Doki/engines/doki_core/spec/rails_helper.rb:7:in `<top (required)>'
from /Users/typeoneerror/.rvm/gems/ruby-2.1.2@doki/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in …Run Code Online (Sandbox Code Playgroud) 我想用1个元素填充一个数组但是5次.到目前为止我得到了什么.
str = 1234
a = []
5.times { a << str }
puts a # => 1234, 1234, 1234, 1234, 1234
Run Code Online (Sandbox Code Playgroud)
它有效,但这不是红宝石的方式.有人能指出我正确的方向来初始化一个具有5倍相同值的数组吗?
之间的差异after_create,after_save以及after_commit在Rails的是:
after_save 在创建和更新对象时调用after_commit 在创建,更新和销毁时调用. after_create 仅在创建对象时调用这是它们之间的唯一区别还是存在其他主要差异?
有没有办法制作一个可以接受参数的方法,但也可以在没有参数的情况下调用,在这种情况下,参数nil如下所示?
some_func(variable)
some_func
Run Code Online (Sandbox Code Playgroud) 我试图安装vagrant插件vbguest,但在终端中遇到以下错误:
$ vagrant plugin install vbguest
Installing the 'vbguest' plugin. This can take a few minutes...
/usr/lib/ruby/2.3.0/rubygems/specification.rb:946:in `all=': undefined method `group_by' for nil:NilClass (NoMethodError)
from /usr/lib/ruby/vendor_ruby/vagrant/bundler.rb:275:in `with_isolated_gem'
from /usr/lib/ruby/vendor_ruby/vagrant/bundler.rb:231:in `internal_install'
from /usr/lib/ruby/vendor_ruby/vagrant/bundler.rb:102:in `install'
from /usr/lib/ruby/vendor_ruby/vagrant/plugin/manager.rb:62:in `block in install_plugin'
from /usr/lib/ruby/vendor_ruby/vagrant/plugin/manager.rb:72:in `install_plugin'
from /usr/share/vagrant/plugins/commands/plugin/action/install_gem.rb:37:in `call'
from /usr/lib/ruby/vendor_ruby/vagrant/action/warden.rb:34:in `call'
from /usr/lib/ruby/vendor_ruby/vagrant/action/builder.rb:116:in `call'
from /usr/lib/ruby/vendor_ruby/vagrant/action/runner.rb:66:in `block in run'
from /usr/lib/ruby/vendor_ruby/vagrant/util/busy.rb:19:in `busy'
from /usr/lib/ruby/vendor_ruby/vagrant/action/runner.rb:66:in `run'
from /usr/share/vagrant/plugins/commands/plugin/command/base.rb:14:in `action'
from /usr/share/vagrant/plugins/commands/plugin/command/install.rb:32:in `block in execute'
from /usr/share/vagrant/plugins/commands/plugin/command/install.rb:31:in `each'
from /usr/share/vagrant/plugins/commands/plugin/command/install.rb:31:in `execute'
from /usr/share/vagrant/plugins/commands/plugin/command/root.rb:56:in `execute' …Run Code Online (Sandbox Code Playgroud) 我有一个 react native 项目,想为 iOS 本机细节安装可可豆荚,但安装失败,我在 Mac book pro 上安装了 ruby ruby 2.5.1p57
我已将错误发布下来,将不胜感激
pod install
Analyzing dependencies
Fetching podspec for `DoubleConversion` from `../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec`
Fetching podspec for `Folly` from `../node_modules/react-native/third-party-podspecs/Folly.podspec`
Fetching podspec for `GLog` from `../node_modules/react-native/third-party-podspecs/GLog.podspec`
Fetching podspec for `React` from `../node_modules/react-native`
Fetching podspec for `react-native-fetch-blob` from `../node_modules/react-native-fetch-blob`
Fetching podspec for `react-native-google-maps` from `../node_modules/react-native-maps`
Fetching podspec for `react-native-maps` from `../node_modules/react-native-maps/`
Fetching podspec for `yoga` from `../node_modules/react-native/ReactCommon/yoga`
Downloading dependencies
Using DoubleConversion (1.1.5)
Using Folly (2016.09.26.00)
Installing GLog (0.3.4)
#<Thread:0x00007fd5349ba008@/usr/local/lib/ruby/gems/2.5.0/gems/cocoapods-1.5.3/lib/cocoapods/executable.rb:166 run> terminated …Run Code Online (Sandbox Code Playgroud) ruby ×10
activeadmin ×1
activerecord ×1
callback ×1
capybara ×1
cocoapods ×1
ios ×1
methods ×1
optimization ×1
profiling ×1
react-native ×1
respond-to ×1
rspec ×1
rspec-rails ×1
ubuntu ×1
vagrant ×1
virtualbox ×1