如何创建thor :: group生成器作为my_command的args

在我的gem中,我想要一个带有args的可执行命令,如下所示: foo generate project foo generate config foo say_hi 所以我做了 富/斌/富 #!/usr/bin/env ruby require ‘foo’ Foo::Foo.start 和Foo文件在foo / lib / thor / foo.rb中 module Foo class Foo < Thor desc "generate [WHAT]" def generate(*args) end desc "say_hi" def say_hi(*args) …. end end end 和foo / lib / thor / generators / project.rb和foo / lib / […]

由于“mysql2”gem,我无法运行“bundle update”

我在Gemfile中有这个: gem ‘mysql2’ 但是当我运行bundle update时 ,我收到以下错误消息: An error occurred while installing mysql2 (0.3.16), and Bundler cannot continue. Make sure that `gem install mysql2 -v ‘0.3.16’` succeeds before bundling. 我试着把它移到生产部分,像这样: group :production do gem ‘mysql2’ end 但是在运行bundle更新后 ,结果是一样的。 此部分仅在生产模式下处理,还是不处理? 如何摆脱localhost上的此错误消息? 编辑:整个错误消息: Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension. /Users/radek/.rvm/rubies/ruby-1.9.3-p385/bin/ruby extconf.rb checking for ruby/thread.h… *** extconf.rb […]

Http流媒体与瘦&eventmachine

我正在玩EM来实现流媒体和并发。 我遇到了流式传输问题…我运行以下机架应用https://gist.github.com/1394840使用 $ rackup -s thin -p 3000 async_app.ru 在使用$ ab -c 10 -n 20 http://localhost:3000/ ,应用程序似乎接受了parellel请求。 大! 我希望它同时实现流媒体。 当我在Firefox8中测试它时,它运行良好。 使用$ curl -i http://localhost:3000/ ,结果也像预期的那样流式传输! 但后来在IE和Chrome中进行测试时,流式传输失败了,也就是说,三条线路只在请求发出后5秒内一起出现…… 我怀疑如果我错过了浏览器所需的东西? 我注意到没有Transfer-Encoding:chunked在响应头Transfer-Encoding:chunked ,所以它重要吗? 如果是这样,那是Thin的问题吗? 如何使用精简版或Chrome实现流式传输? 谢谢!

麻烦包括在铁轨上的ruby中的httparty

我一直在尝试在rails代码中使用HTTParty sudo gem install httparty 从命令行我现在可以成功地做到 httparty “http://twitter.com/statuses/public_timeline.json” 当我在我的rails应用程序中尝试此操作时 require ‘rubygems’ require ‘httparty’ class FooController < ApplicationController include HTTParty def bar blah = HTTParty.get("http://twitter.com/statuses/public_timeline.json") end end 我收到错误消息“没有这样的文件加载 – httparty” 我怀疑我的环境有问题吗?

如何设置’attr_accessible’以便不允许使用Ruby on Rails访问任何模型的字段?

如果在模型文件中我只有这个代码: class Users < ActiveRecord::Base end 这意味着什么? 是否可以访问与模型相关的所有属性? 如何设置’attr_accessible’以便不允许访问该模型的任何字段?

Ruby链接为字符串中的url

有一些关于使用正则表达式链接文本的post。 最受欢迎的是这篇文章 。 不过我的规格有点棘手: describe TextFormatter do def l(input) TextFormatter.gsub_links!(input){|link| “!!#{link}!!”} end it “should detect simple links” do l(“http://www.cnn.com”).should == “!!http://www.cnn.com!!” end it “should detect multi links” do l(“http://www.cnn.com http://boats.com?help.asp”).should == “!!http://www.cnn.com!! !!http://boats.com?help.asp!!” end it “should compensate for parans properly” do l(“(http://this.is?hello_world)”).should == “(!!http://this.is?hello_world!!)” end it “should ignore existing links” do s = ” http://sam.com […]

Ruby检查可读性?

有没有办法让检查输出更具可读性? 在Perl中,有Data::Dumper ,它使输出更容易阅读。

如何找出什么是拦截’method_missing’

使用Ruby 1.8.6 / Rails 2.3.2 我注意到在我的任何ActiveRecord模型类上调用的任何方法都返回nil而不是NoMethodError。 除了烦人之外,这find_by_name破坏动态查找器( find_by_name , find_by_id等),因为即使存在记录,它们也始终返回nil 。 不从ActiveRecord :: Base派生的标准类不受影响。 有没有办法在ActiveRecord :: Base之前跟踪什么是拦截method_missing? 更新: 切换到1.8.7后,我发现(感谢@MichaelKohl)will_paginate插件首先处理method_missing。 但是will_paginate已经存在了我们的系统(未经改动)很长一段时间,罪魁祸首必须是后来的东西。 任何想法如何看到这个链中的下一步? 更新: 事实certificate,有一个gem(annotate-2.4.0)是猴子修补ActiveRecord::Base#method_missing作为空白方法。 卸载gem解决了我的问题。 虽然没有给出的答案实际上找到了问题,但@Yanhao的答案最接近,因为它只需要一个小调整来发现有问题的别名方法

我应该将Google Web Toolkit用于我的新网络应用吗?

我想创建一个数据库支持的交互式AJAX webapp,它具有自定义(特定类型的事件,编辑)日历系统。 这将涉及相当多的JavaScript和AJAX,我想到了用于接口的Google Web Toolkit和用于服务器端的Ruby on Rails。 Google Web Toolkit是否可靠且良好? 如果我选择Google Web Toolkit,可能会有哪些隐患? 可以轻松地将它与服务器端的Ruby on Rails结合起来吗? 或者我应该尝试直接使用像jQuery这样的JavaScript库? 我没有Web开发经验,除了一些HTML,但我是一个经验丰富的程序员(c ++,java,c#),我想只使用这个项目的免费工具。

邮件程序错误丢失模板

你好, 当我尝试执行操作时,我遇到了ActionMailer的问题: rake send_email 我收到一个错误: rake aborted! ActionView::MissingTemplate: Missing template user_mailer/mailer with “mailer”. Searched in: * “user_mailer” 这是我的: 邮寄/ user_mailer.rb class UserMailer < ActionMailer::Base default from: "from@example.com" def mailer(user) @user = user mail(to: @user.email, subject: 'Test') end end 视图/ user_mailer文件/ mailer.html.erb Sample mail. 视图/ user_mailer文件/ mailer.text.erb Sample mail. LIB /任务/ emails_task.rake desc ‘send email’ task […]