草庐IT

cached_obj_get

全部标签

ruby-on-rails - rails : Plus sign in GET-Request replaced by space

在Rails3(Ruby1.9.2)中我发送一个请求StartedGET"/controller/action?path=/41_+"但是参数列表是这样的:{"path"=>"/41_","controller"=>"controller","action"=>"action"}这里出了什么问题?-、*或.符号工作正常,只是+将被空格替换。 最佳答案 这是正常的URL编码,theplussignisashorthandforaspace:Withinthequerystring,theplussignisreservedasshor

ruby - Ruby 中 const_get 的混淆行为?

根据文档mod.const_get(sym)“返回mod中命名常量的值。”我也知道const_get默认情况下可能会查找接收者的继承链。所以以下工作:classA;HELLO=:hello;endclassB:hello我也知道Ruby中的类是Object的子类,因此您可以使用const_get来查找“全局”常量,即使接收方是一个普通类:classC;endC.const_get(:Array)#=>Array然而,这就是我感到困惑的地方——模块不继承Object。那么,为什么我仍然可以使用const_get从模块中查找“全局”常量?为什么以下方法有效?moduleM;endM.con

ruby-on-rails - has_many :through with counter_cache

据我了解,在定义:counter_cache选项时,应在包含belongs_to声明的模型上指定它。所以我有点不确定在通过关联使用has_may时如何处理这个问题(因为我相信在这种情况下不使用belongs_to声明):classPhysician:appointmentsendclassAppointmentappointment_countendclassPatient我希望使用:counter_cache选项来更有效地查找属于医生的患者数量。myPhysician.patients.count仅供引用:Rails3.1干杯 最佳答案

ruby-on-rails - 为什么 RSpec 的方法 "get"、 "post"、 "put"、 "delete"在 gem(或 Rails 外部)的 Controller 规范中不起作用?

我不是Rails或Rspec的新手,但我是制作gems的新手。当我测试我的Controller时,REST方法“get”、“post”、“put”、“delete”给我一个未定义的方法错误。您将在下面找到代码,但如果您更喜欢在馅饼中查看它,clickhere.谢谢!这是我的spec_helper:$LOAD_PATH.unshift(File.dirname(__FILE__))$LOAD_PATH.unshift(File.join(File.dirname(__FILE__),'..','lib'))require'rubygems'require'active_support'u

ruby-on-rails - 抽取 Assets :precompile gets killed when there is a console session open in production

在我托管在digitalocean上的生产服务器上,如果有帮助的话,Ubuntu12.04,我有RoR4和rake10.1.1。当我部署时,我运行rakeassets:precompile,我注意到一个奇怪的问题,如果我在执行此操作时打开了一个railsconsolesession,我得到以下输出~#rakeassets:precompile~#Killed主要是很烦人,但我希望解决这个问题的原因是在雇用新开发人员时,会有部署/控制台冲突噩梦。谢谢,布莱恩 最佳答案 您的预编译进程可能被终止,因为您的内存不足。您可以通过在另一个ss

ruby-on-rails - 未定义方法 `cache' 为 nil :NilClass after upgrading to rails 4. 2.5.1

从Rails4.2.5升级到最近发布的4.2.5.1时,我遇到了这个错误。此错误仅适用于具有呈现无效状态的before_filter的规范,例如renderfile:"public/422",status::unauthorized。我在ruby​​-2.2.2和ruby​​-2.3.0上都收到了这个错误错误存在于action_view解析器方法中,暗示@cache值为nil。然而,在initialize方法中它应该被实例化:@cache=Cache.new我仍在研究可重现的样本,但到目前为止我还不知道@cache怎么可能是nil。这些是在我的test.rb环境中设置的配置变量conf

ruby-on-rails - 可以安全删除 rails tmp/cache/assets 文件吗?

我似乎在命名为example的子文件夹中有很多它们sprockets%2F76920e6913c3390459175ac8e6dfd44a3它们似乎包含二进制数据。它们的用途是什么,为什么有这么多,最重要的是,可以安全地移除它们吗?他们需要永远的scp。 最佳答案 是的!您可以删除整个tmp目录,它将被重新创建。 关于ruby-on-rails-可以安全删除railstmp/cache/assets文件吗?,我们在StackOverflow上找到一个类似的问题:

ruby-on-rails - counter_cache 与 has_many :through

我刚刚创建了一个counter_cache字段,Controller看起来像这样。@users=User.where(:sex=>2).order('received_likes_count')User.rb中的关联是has_many:received_likes,:through=>:attachments,:source=>:likes,:dependent=>:destroy问题是counter_cache是在Like.rb的belong_to中声明的,我不知道如何告诉它它是用于has_many:through关联。belongs_to:user,:counter_cache=>

ruby-on-rails - Rails : how to get the current host, 或用它构建 URL?

这个问题在这里已经有了答案:GettingtheHostnameorIPinRubyonRails(12个答案)关闭8年前。我需要使用主机构建具有不同端口的URL。例如,如果主机是example.com,我需要生成类似http://example.com:8080/的URL我需要它是便携的,所以当我在本地环境中时,它会显示http://localhost:8080/相反。有什么想法吗?

ruby-on-rails - RSpec 测试使用 GET 参数重定向到 URL

假设我有一个带有redirect_to_baz方法的FoosController。classFoosController我正在使用spec/controllers/foos_controller_spec.rb对此进行测试:require'spec_helper'describeFoosController,:type=>:controllerdodescribe"GETredirect_to_baz"doit"redirectstoexample.comwithparams"doget:redirect_to_bazexpect(response).toredirect_to"htt