草庐IT

local-copies-of-documentation

全部标签

ruby-on-rails - 为什么 Ruby on Rails 使用 http ://0. 0.0.0 :3000 instead of http://localhost:3000?

当我尝试按照官方“入门”RubyonRails教程进行操作时,很快就出错了。基本上它说:…navigatetohttp://localhost:3000.YoushouldseeRails’defaultinformationpage.但是当我按照说明操作时,我得到了=>Rails2.3.4applicationstartingonhttp://0.0.0.0:3000在尝试了这两个地址之后,我知道它们指向同一件事,但是有人可以向我解释为什么RubyonRails使用http://0.0.0.0:3000而不是http://localhost:3000?有没有办法让WEBrick服务器

ruby-on-rails - 测试 : how to focus on behavior instead of implementation without losing speed?

似乎有两种完全不同的测试方法,我想引用它们。问题是,这些意见是在5年前(2007年)提出的,我很感兴趣,从那以后发生了什么变化,我应该走哪条路。BrandonKeepers:Thetheoryisthattestsaresupposedtobeagnosticoftheimplementation.Thisleadstolessbrittletestsandactuallyteststheoutcome(orbehavior).WithRSpec,Ifeellikethecommonapproachofcompletelymockingyourmodelstotestyourcontr

ruby-on-rails - 类型错误 : no implicit conversion of Symbol into Integer

我在尝试更改散列的值时遇到了一个奇怪的问题。我有以下设置:myHash={company_name:"MyCompany",street:"Mainstreet",postcode:"1234",city:"MyCity",free_seats:"3"}defcleanupstringstring.titleizeenddefformatoutput=Hash.newmyHash.eachdo|item|item[:company_name]=cleanup(item[:company_name])item[:street]=cleanup(item[:street])output当我

ruby - 库未加载 :/opt/local/lib/libssl. 1.0.0.dylib (LoadError)

我刚刚发现我无法再gempush…并且一些挖掘导致我需要更新我的RVMSSL证书。我运行了rvmosx-ssl-certsstatusall但这给了我:/Users/davesag/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in`require':dlopen(/Users/davesag/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/x86_64-darwin12.4.0/openssl.bundle,9

ruby - 强制 bundle 安装使用 https ://instead of git://for GitHub-based gems

我正在尝试构建一个Rails项目,因为我正在使用的主机无法访问Internet的git://协议(protocol)(端口9418),我收到如下错误Fetchinggit://github.com/pivotal/jasmine.gitfatal:unabletoconnecttogithub.com:github.com[0:192.30.252.130]:errno=Connectionrefused运行bundleinstall时。GemFile中的相关行没有指定git://作为协议(protocol),它只是指向GitHub作为gem的源gem'jasmine',:github

ruby - 警告 : Can't verify CSRF token authenticity in case of API development

我现在正在使用RubyonRails开发网络API。当Rails应用程序收到没有任何csrftoken的POST请求时,将出现以下错误消息。因为该应用没有View。WARNING:Can'tverifyCSRFtokenauthenticity所以我的问题是在这种情况下如何安全地逃避csrftoken检查?非常感谢您。 最佳答案 你可以通过添加skip_before_filter:verify_authenticity_token到你的Controller。这样,所有传入Controller的请求都会跳过:verify_authen

ruby - "wrong number of arguments (1 for 0)"在 Ruby 中是什么意思?

“参数错误:参数数量错误(1代表0)”是什么意思? 最佳答案 当您定义一个函数时,您还定义了该函数需要工作的信息(参数)。如果它被设计为在没有任何额外信息的情况下工作,并且你传递了一些信息,你就会得到那个错误。例子:不接受参数:defdogend接受参数:defcat(name)end当你调用它们时,你需要用你定义的参数来调用它们。dog#worksfinecat("Fluffy")#worksfinedog("Fido")#ReturnsArgumentError(1for0)cat#ReturnsArgumentError(0f

ruby-on-rails - rails : How to make Date strftime aware of the default locale?

我在environment.rb中将我的默认语言环境设置为de(德语)。我还看到了德语的所有错误消息,因此服务器选择了语言环境。但是当我尝试使用strftime打印日期时,如下所示:some_date.strftime('%B,%y')它以英语(January,11)打印,而不是预期的德语(Januar,11)。如何根据默认语言环境打印日期? 最佳答案 使用l(localize的别名)方法代替原始strftime,如下所示:l(date,format:'%B%d,intheyear%Y')参见here获取更多信息。您还可以定义“命名

ruby-on-rails - rails : Should partials be aware of instance variables?

例如,RyanBates的nifty_scaffolding就是这样做的编辑.html.erb'form'%>new.html.erb'form'%>_form.html.erb那种隐藏的状态让我觉得不舒服,所以我通常喜欢这样做编辑.html.erb'form',:locals=>{:object=>@my_object}%>_form.html.erb那么哪个更好:a)让部分访问实例变量或b)传递部分它需要的所有变量?最近我一直选择b),但我确实遇到了一些问题:some_action.html.erb'partial',:locals=>{:son=>a_son}%>_partial

ruby-on-rails - Rspec 输出格式 : Documentation

当我使用rakerspec运行rspec并且我的测试不正常时,我收到一条错误消息。但是,当我的测试正常时,我只会得到“..”。没有其他输出。我怎样才能让它打印出类似的东西:AUser....canonlyhaveonenameAUser....can... 最佳答案 来自rspec帮助页面$rspec--helpUsage:rspec[options][filesordirectories]-f,--formatFORMATTERChooseaformatter[p]rogress(default-dots)[d]ocumentat