测试ActiveSupport :: TimeWithZone对象是否相等

有人可以解释d1如何大于d2? 他们是相同的日期(或至少他们看起来如何)。 Loading development environment (Rails 3.0.8) ruby-1.9.2-p180 :001 > d1 = Event.first.updated_at => Thu, 22 Sep 2011 02:24:28 PDT -07:00 ruby-1.9.2-p180 :002 > d2 = Time.zone.parse(“2011-09-22T02:24:28-07:00”) => Thu, 22 Sep 2011 02:24:28 PDT -07:00 ruby-1.9.2-p180 :003 > d1.class => ActiveSupport::TimeWithZone ruby-1.9.2-p180 :004 > d2.class => ActiveSupport::TimeWithZone ruby-1.9.2-p180 :005 > d1 > d2 => true […]

无法使用Ruby和net / ssh连接密钥

我无法使用’net-ssh’gem通过ssh从ruby连接,获得Net :: SSH :: AuthenticationFailed。 代码如下 require ‘net/ssh’ keys = [“path_to_private_key”] Net::SSH.start(‘host’, ‘user’,:keys => keys, :verbose => :debug) do |ssh| #ssh code end 直接从命令行使用ssh: ssh -i user@host 我的ssh API有错吗? 我尝试了’user @ host’和’user’作为用户名,结果相同。 这是调试输出: D, [2011-07-26T19:42:00.135148 #3511] DEBUG — net.ssh.transport.session[140b040]: establishing connection to host:22 D, [2011-07-26T19:42:00.164190 #3511] DEBUG — net.ssh.transport.session[140b040]: connection established I, [2011-07-26T19:42:00.164344 #3511] INFO […]

当stdin不是终端时的Ruby提示(对于Notepad ++显式)?

我是Notepad ++用户。 我喜欢该软件的一个特性是你可以在UI中使用“控制台”(这不是一个真正的终端),并且你可以从那里运行一些命令行解释器。 仅供参考,要使控制台在Notepad ++中运行,您需要安装NppExec插件,然后转到Menu > Plugins > NppExec > Execute…并输入您想要的任何可执行文件(exe,批处理等)然后按OK。 将启动控制台,您将在那里看到程序的输出,如果是交互式shell,您还可以输入命令。 例如 对于实际的DOS提示符,运行cmd.exe 对于Python提示符,运行python.exe -i 。 从Python帮助: -i inspect interactively after running script; forces a prompt even if stdin does not appear to be a terminal; also PYTHONINSPECT=x -i inspect interactively after running script; forces a prompt even if stdin does not appear to […]

严重依赖Ruby数组重新排序

我需要根据依赖元素重新排序数组。 如果一个元素是一个数组(具有依赖性),那么该数组的第二个元素是依赖项,并且需要在该数组之前。 然后删除所有依赖关系信息,因为我们不再需要,我们返回一个更正顺序的数组。 # array1 = [[‘a’], [‘b’,’c’], [‘c’,’a’]] # ordered = [‘a’, ‘c’, ‘b’] # logic: c comes before b, a comes before c 以下是我认为过度设计的方法: array1.each_with_index do |ar, i| # ignore elements without dependencies if ar.count > 1 # get dependency dep = ar[1] # get index for element where this dependency is first […]

Rails current_path Helper?

我正在使用以下路由条件的Rails 3.2应用程序: scope “(:locale)”, locale: /de|en/ do resources :categories, only: [:index, :show] get “newest/index”, as: :newest end 我有一个控制器,具有以下内容: class LocaleController < ApplicationController def set session[:locale_override] = params[:locale] redirect_to params[:return_to] end end 我在模板中使用这样的东西: = link_to set_locale_path(locale: :de, return_to: current_path(locale: :de)) do = image_tag ‘de.png’, style: ‘vertical-align: middle’ = t(‘.languages.german’) 我想知道为什么在Rails中不存在帮助器,例如current_path ,这能够推断出我们当前使用的路由,并且重新路由到它包括新选项。 我遇到的问题是使用redirect_to :back ,将用户推回/en/…….. (或/de/… ),这会带来糟糕的体验。 […]

Ajaxified Star Rating System未正确更新

我使用本教程实施了星级评分系统 http://eighty-b.tumblr.com/post/1569674815/creating-an-ajaxified-star-rating-system-in-rails-3 Ajax完美运行,直到我添加Javascript,提交表单/在给定用户进行更改后保存数据。 出于某种原因,它将遍历我的索引页面上的所有元素,并在所选对象上提交正确的整数值,但随后在其余部分上提交一堆NIL值。 我只希望它更新那个ONE对象。 ( 如何在Javascript中提交相应的图书ID? ) 新的铁路请帮助:) VIEWS index.hrml.erb(书籍) <table id="book”> #####This is my partial for my form ‘ratings/rating’, :locals =>{:book => book} %> _rating.html.erb Avg. Rating { :class => ‘rating_ballot’ }, :remote => true do |f| %> “rating”, :id=>”1″}) %> ‘rating_button’) %> “rating”, :id=>”2″}) %> ‘rating_button’) %> “rating”, :id=>”3″}) %> ‘rating_button’) %> […]

延迟::带模块的工作

Delayed :: Job是否可以使用模块? 我遇到了麻烦: module SomeModule class SomeClass def regular_method self.delay.long_method “test” end def long_method data puts data end end end 错误信息: [Worker(host:leo pid:10480)] SomeModule::SomeClass#long_method failed with NoMethodError: undefined method `long_method’ for # – 4 failed attempts [Worker(host:leo pid:10480)] 1 jobs processed at 9.1484 j/s, 1 failed …

使用fb_graph Ruby gem从Facebook检索朋友位置

我正在尝试使用gem: fb_graph检索所有用户朋友的位置。 (1.7.2版) 我的权限是: publish_stream,read_friendlists,offline_access,friends_location,user_location 我已经对用户进行了身份validation并存储了脱机访问令牌及其facebook ID。 user = User.find_by_email(“person@email.com”) facebook_user = FbGraph::User.fetch(user.facebook_identifier, :access_token => user.facebook_access_token) facebook_user.friends.map(&:location) => [nil, nil…] 当我从Facebook内部检查权限时,它说我可以访问朋友位置: http://grab.by/a1Qm 我的问题是,当我尝试获取朋友的位置时,它总是返回零。 我有正确的权限设置,我知道每个人的位置不应该是零。 有没有人对如何获取朋友位置有任何建议或指示? 谢谢!

Heroku部署错误

在Windows环境中,我尝试部署到Heroku时收到以下错误 C:/Ruby/lib/ruby/gems/1.8/gems/heroku-1.9.13/lib/heroku/commands/base.rb:32:在 ‘:没有这样的文件或目录 – 来自C的git remote(Errno :: ENOENT):/ Ruby / lib / ruby​​ / gems / 1.8 / gems / ethoku-1.9.13 / lib /heroku /commands / ba se.rb:32 :在shell’ from C:/Ruby/lib/ruby/1.8/fileutils.rb:121:in chdir’来自C:/Ruby/lib/ruby/1.8/fileutils.rb:121:in cd’ from C:/Ruby/lib/ruby/gems/1.8/gems/heroku-1.9.13/lib/heroku/commands/ba se.rb:32:in shell’from C:/Ruby/lib/ruby/gems/1.8/gems/ heroku-1.9.13 / lib / heroku / commands / ap p.rb:52:in create’ from C:/Ruby/lib/ruby/gems/1.8/gems/heroku-1.9.13/lib/heroku/command.rb: 48:in发送’来自C:/Ruby/lib/ruby/gems/1.8/gems/heroku-1.9.13/lib/heroku/command.rb:48:in run_internal’ from C:/Ruby/lib/ruby/gems/1.8/gems/heroku-1.9.13/lib/heroku/command.rb: […]

路由机架问题

我正在使用Ruby on Rails 3,我想将一些URL路由到一些Rack中间件。 也就是说,如果用户尝试浏览http://.com/api/user/1 ,系统应考虑在Rack文件之前运行,然后继续执行请求。 我有一个Rack :: Api:用户位于lib/rack/api/user文件夹中。 从RoR官方文档中我发现了这个: Mount a Rack-based application to be used within the application. mount SomeRackApp, :at => “some_route” Alternatively: mount(SomeRackApp => “some_route”) All mounted applications come with routing helpers to access them. These are named after the class specified, so for the above example the helper is either […]