在Ruby解释器段错误之后,是否有可能从核心文件中获取Ruby回溯?

注意:我使用的是我在使用libxml-ruby gem时遇到的段错误来说明问题,但我已经修复了我所说的gem的问题。 这个问题的真正意义在于从gdb和核心文件查看Ruby回溯(即解释器在Ruby代码无法处理exception时打印的内容),解释器本身遇到分段错误。 在生成XML文档的过程中,我遇到了一个奇怪的段错误: /railsroot/vendor/isolated/ruby-1.8/gems/libxml-ruby-1.1.2/lib/libxml/node.rb:123: [BUG] Segmentation fault ruby 1.8.7 (2011-02-18 patchlevel 334) [x86_64-linux], MBARI 0x6770, Ruby Enterprise Edition 2011.03 Aborted 更新1:此分段也在vanilla Ruby(MRI)下进行。 我已经打开了corefiles并查看了gdb中的backtrace(参见问题的结尾)。 我可以看到解释器崩溃的地方,谷歌搜索导致了许多有希望的结果 。 除了解释器回溯之外,我还想看到的是Ruby代码本身的回溯(即从解释器的角度来看的回溯)。 我希望在gdb中加载核心将允许我调用一些解释器函数来打印出解释代码的堆栈。 有任何想法吗? 对于好奇的人来说,这是核心和回溯: : foo@bar; ulimit -c unlimited : foo@bar; RAILS_ENV=production ./script/runner script/feeds/batchfeed.rb –config config/feeds/$feed.yml –timer /tmp/$feed.timer –gzip –output /tmp/$feed.xml.gz /railsroot/vendor/isolated/ruby-1.8/gems/libxml-ruby-1.1.2/lib/libxml/node.rb:123: [BUG] Segmentation fault ruby 1.8.7 (2011-02-18 patchlevel […]

与Rails中的url_for相反的是什么? 获取路径并生成解释路线的函数?

大脑有点油炸….我如何得到:控制器的哈希和来自relative_path的动作? 这基本上与url_for相反。 在下面的例子中,“some_function”是我正在寻找的神秘函数名称……我知道它很简单,只是记不住或者似乎无法在文档中找到它。 像这样: some_function(‘/posts/1/edit’) => {:controller => ‘posts’, :action => ‘edit’, :id => ‘1’}

为什么真相&&“字符串”返回“字符串”

假设我有类似的东西 true && true #=> true 这是有道理的,所以我尝试这样的事情: true && “dsfdsf” #=> “dsfdsf” 这让我感到惊讶,因为我经常会做一些事情,比如if something && something和if something && something ,我总是认为那是评估为真的并且会回归真实。 进一步的实验做的事情如下: jruby-1.7.3 :009 > “ad” && “dsf” => “dsf” jruby-1.7.3 :010 > “ad” && “sdfd” && nil => nil jruby-1.7.3 :011 > “ad” && nil && “sdf” => nil 如果全部为真,或者它找到的第一个假值,Ruby似乎返回最后一个值。 为什么这样做? 这是一个正确的心理模型吗?

获取资产管道路径中的Gem供应商文件

我创建了一个gem,其中包含来自bootstrap-sass和bootstrap本身的样式表和javascripts的供应商目录。 目录结构是bootstrap-sass-gem / vendor / assets / javascripts 和 引导 – 萨斯 – gem/供应商/资产/样式表 我在测试项目中需要gem,但每当我尝试从gem中获取某些内容时,我都会收到Sprockets::FileNotFound错误。 例如,在application.css中我添加了*= require bootstrap 。 bootstrap位于bootstrap-sass-gem/vendor/assets/stylesheets/bootstrap.scss ,因此我的计算应该包含在资产管道中。 我正在运行RVM Ruby 1.9.2和Rails 3.1。 这是我的配置文件: $:.push File.expand_path(“../lib”, __FILE__) # Maintain your gem’s version: require “bootstrap-sass-gem/version” # Describe your gem and declare its dependencies: Gem::Specification.new do |s| s.name = “bootstrap-sass-gem” s.version = BootstrapSassGem::VERSION s.authors = […]

如何在请求范围之外访问Sinatra的Logger

似乎Sinatra的记录器仅在请求处理程序中可用(请参阅https://github.com/sinatra/sinatra#logging ),但如果我想在其他地方使用记录器,例如在帮助程序方法或配置中,该怎么办?钩? Sinatra记录仪是否可通过其他方式获得?

在另一个苗条文件中包含一个苗条文件

我正在开发一个静态网站(所以没有真正的服务器支持),我想在另一个网站中包含一个小的细长片段,可能会将变量传递给它。 这可能吗? 在rails中很容易,虽然render方法,但我不知道如何在slim上做(显然load方法不适用于slim)。

Rails多个belongs_to赋值

特定 用户: class User < ActiveRecord::Base has_many :discussions has_many :posts end 讨论: class Discussion < ActiveRecord::Base belongs_to :user has_many :posts end post: class Post < ActiveRecord::Base belongs_to :user belongs_to :discussion end 我目前正在控制器中初始化post @post = current_user.posts.build(params[:post]) 我的问题是,如何设置/保存/编辑@post模型,以便设置post和讨论之间的关系?

通过FTP通过TLS / SSL连接到未经认证的主机

我从中获取文件的供应商正在通过SSL从FTP更改为FTP。 我正在尝试将我的代码从net/ftp更新为net/ftptls 我需要连接的新主机未经过认证,我的脚本会报告此错误。 hostname与服务器证书不匹配 供应商不会解决这个问题。 看看/usr/lib/ruby/1.8/net/ftptls.rb我认为通过猴子修补FTPTLS来忽略不受信任的主机并不会太难。 我尝试将verify_mode更改为OpenSSL::SSL::VERIFY_NONE并注释掉post_connection_check`行。 既没有奏效。 有关如何做到这一点的任何想法? require ‘socket’ require ‘openssl’ require ‘net/ftp’ module Net class FTPTLS < FTP def connect(host, port=FTP_PORT) @hostname = host super end def login(user = "anonymous", passwd = nil, acct = nil) store = OpenSSL::X509::Store.new store.set_default_paths ctx = OpenSSL::SSL::SSLContext.new('SSLv23') ctx.cert_store = store ctx.verify_mode = OpenSSL::SSL::VERIFY_PEER ctx.key = nil […]

安装/捆绑gem unf_ext -v’0.0.6’时出错

我正在尝试捆绑unf_ext -v ‘0.0.6’但我一直收到此错误: Gem::Ext::BuildError: ERROR: Failed to build gem native extension. checking for main() in -lstdc++… yes checking for ruby/encoding.h… yes creating Makefile make “DESTDIR=” clean make “DESTDIR=” compiling unf.cc In file included from unf.cc:1: In file included from ./unf/normalizer.hh:4: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/vector:265: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/__bit_reference:15: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/algorithm:628: […]

如何在update_attributes期间以管理员身份跳过validation?

当我尝试将用户编辑为管理员时,我想跳过validation。 模型 class User … attr_accessible :company_id, :first_name, :disabled, as: :admin 调节器 class Admin::UsersController … def update @user = User.find(params[:id]) @user.update_attributes(params[:user], as: :admin) redirect_to edit_admin_user_path(@user), :notice => “User Account Updated” end 所以我尝试将update操作更改为 def update @user = User.find(params[:id]) @user.attributes = params[:user] @user.save(validate: false) redirect_to edit_admin_user_path(@user), :notice => “User Account Updated” end 但后来我没有访问set :disabled和:company_id属性,因为我不知道在哪里设置as: :admin