Tag: ruby 2.0

Rails 4.1.6会话ID

如何从请求对象获取会话ID。 下面的代码可以在Rails 3中用来获取会话ID。 但是这在Rails 4.1.6和Ruby 2.1.3中似乎不再起作用 request.session_options[:id]

无法使用Ruby 2.0运行Unicorn

在我的ubuntu机器上,我可以在ruby 1.9.3上运行独角兽,但是,它似乎不适用于ruby 2.0。 知道为什么吗? root@dev:/home/karan# rvm use 1.9 Using /usr/local/rvm/gems/ruby-1.9.3-p429 root@dev:/home/karan# unicorn -v unicorn v4.6.3 root@dev:/home/karan# rvm use 2.0 Using /usr/local/rvm/gems/ruby-2.0.0-p195 root@dev:/home/karan# unicorn -v /usr/local/rvm/rubies/ruby-2.0.0-p195/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require’: cannot load such file — unicorn/launcher (LoadError) from /usr/local/rvm/rubies/ruby-2.0.0-p195/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require’ from /usr/bin/unicorn:3:in `’

使用Rails 4.0进行自定义error handling

我正在使用Ruby 2.0和Rails 4.0构建Ruby on Rails api。 我的应用程序几乎只是一个JSON API,所以如果发生错误(500,404),我想捕获该错误并返回格式良好的JSON错误消息。 我试过这个并且还: rescue_from ActionController::RoutingError, :with => :error_render_method def error_render_method puts “HANDLING ERROR” render :json => { :errors => “Method not found.” }, :status => :not_found true end 在我的ApplicationController中。 这些都没有做到这一点(根本没有捕获例外)。 我的谷歌搜索显示这在3.1,3.2之间发生了很大的变化,我找不到任何关于如何在Rails 4.0中做到这一点的好文档。 有人知道吗? 编辑这是我进入404页面时的堆栈跟踪: Started GET “/testing” for 127.0.0.1 at 2013-08-21 09:50:42 -0400 ActionController::RoutingError (No route matches [GET] “/testing”): […]

可以让Rails 4在Windows上运行吗?

我正在研究Rails 4(使用候选版本)项目,现在需要在Windows机器上与某人协作。 我甚至无法得到一个基本的网页,但是:(即使使用Ruby 2.0安装sqlite3也很痛苦。现在,当我试图建立一个网页时(我刚刚创建了一个虚拟/家庭/索引控制器)和视图),我收到此错误: Showing C:/Users/me/RubymineProjects/test_project/app/views/layouts/application.html.erb where line #6 raised: (in C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/turbolinks-1.1.1/lib/assets/javascripts/turbolinks.js.coffee) Extracted source (around line #6): 3 4 TestProject 5 true %> 6 true %> 7 8 9 Rails 4还没有为Windows做好准备吗? 使用Ruby 2.0.0p195。 更新 :根据@szines请求,这是网页输出 http://localhost:3000/rails/info/properties: Ruby version 2.0.0 (x64-mingw32) RubyGems version 2.0.3 Rack version 1.5 Rails version 4.0.0.rc1 JavaScript Runtime JScript Active Record version […]

在AWS EC2上安装Ruby 2.0和Rails 4.0.0beta

在默认的Amazon EC2 Linux安装(Amazon Linux AMI 2012.09.1)上安装Ruby 2.0.0和Rails 4.0.0beta1顺利进行。 但openssl阻碍了(例如http://railsapps.github.com/openssl-certificate-verify-failed.html )并且很奇怪阻止openssl安装或导致RubyGem包管理器安装rails。 我该如何解决这些问题?

电子邮件主题未正确分配Ruby net / smtp

我使用Ruby net / smtp require ‘net/smtp’ 我使用以下方法发送邮件: Net::SMTP.start(SMTP_SERVER) do |smtp| smtp.send_message(message,”mailman-ruby@example.de”,reciepent) end 我想在我发送的邮件中添加一个主题,但在文档中找不到。 到目前为止我尝试过的是将主题放入这样的信息中: <<END_OF_MESSAGE Subject: test message . . . rest of the message END_OF_MESSAGE 不幸的是,这并不成功! 任何人都知道如何使用’smtp / net’设置主题?

即使安装了gem,Ruby 2.0.0也无法加载此类文件

我已经尝试了人们在这里谈到的所有其他解决方案,但没有一个已经帮助/应用。 我编写了一个需要电子表格gem的Ruby脚本。 当我使用ruby myscript.rb正常执行脚本时,需要正常工作,但是在运行chmod +x myscript.rb ,然后尝试使用./myscript.rb运行程序时./myscript.rb以下错误…. /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require’: cannot load such file — spreadsheet (LoadError) from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require’ from /Users/fcangialosi/dev/mTC/parse.rb:2:in `’ from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require’ from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require’ from /Users/fcangialosi/dev/mTC/interpreter.rb:1:in `’ from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require’ from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require’ from ./pmcnp.rb:7:in `’ 我的脚本的开头看起来像这样: #!/usr/bin/ruby require ‘rubygems’ require ‘spreadsheet’ 如果有人有任何想法,我会非常感激。

rspec的.should在Ruby 2中失败(在describe / it块之外)?

在Ruby 2中,使用gem rspec 2.14.1(Ubuntu的最新版本),未安装Rails,为什么会失败? require ‘rubygems’ require ‘rspec’ 3 .should == 3 NoMethodError: undefined method `should’ for 3:Fixnum 多年来我一直依赖方便的习语x .should == y 。 https://www.relishapp.com/rspec/rspec-expectations/v/2-14/docs/syntax-configuration和https://www.relishapp.com/rspec/rspec-expectations/docs/syntax-configuration say默认情况下仍支持此语法。 编辑:在标题中添加“outside describe / it block”,因为这似乎是根本原因。

Overriden方法仍然被调用

我正在使用一个库,该库在数据库中的两个条目之间实现belongs_to关联。 由于这不是我需要的行为,我想通过prepend覆盖此方法。 但是pry告诉我原来的方法仍然被调用。 我仔细检查了一下,我正在使用ruby 2.0。 前置的代码: module Associations module ClassMethods […] #Add the attributeName to the belongsToAttributes #and add a field in the list for the IDs def belongs_to(attr_name) @belongsToAttributes ||= [] @belongstoAttributes << attr_name create_attr attr_name.to_s attribute belongs_to_string.concat(attr_name.to_s).to_sym end def belongsToAttributes @belongsToAttributes end end def self.included(base) base.extend(ClassMethods) end end # prepend the extension Couchbase::Model.send(:prepend, […]

Ruby数组上未定义的方法’to_h’

根据Ruby Array文档 ,只要数组的每个元素是另外两个元素的数组,就有一个方法to_h可用于将数组转换为哈希。 以下示例来自相同的文档 p [[:foo, :bar], [1, 2]].to_h 但是,当我运行上面的代码时,我收到此错误: irb(main):001:0> p [[:foo, :bar], [1, 2]].to_h NoMethodError: undefined method `to_h’ for [[:foo, :bar], [1, 2]]:Array from (irb):1 from E:/RubyInstall/bin/irb:12:in `’ irb(main):002:0> 我的Ruby版本是 C:\>ruby -v ruby 2.0.0p247 (2013-06-27) [x64-mingw32] 我想使用这种技术来回答Stackoverflow上的另一个问题,但是现在我被困住了,因为Ruby的文档function对我不起作用。