草庐IT

CACHE_VAR_TYPE

全部标签

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 - 未定义方法 `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 - 脚手架 ActiveRecord : two columns of the same data type

另一个基本的Rails问题:我有一个数据库表,需要包含对特定数据类型的两个不同记录的引用。假设示例:我正在制作视频游戏数据库。我有一张“公司”表。我想为每个“视频游戏”条目指定一个开发者和一个发布者。我知道如果我想拥有一家公司,我可以这样做:script/generateVideogamecompany:references但我需要同时拥有这两家公司。我宁愿不使用连接表,因为给定的数据类型只能有两个,我需要它们是不同的。看起来答案应该很明显了,但是我在网上到处都找不到。 最佳答案 只是为了稍微整理一下,在您的迁移中,您现在还可以:c

关于Document mapping type name can‘t start with ‘_‘, found: [_update]

在修改elasticsearch时,用_update进行局部修改,修改失败,报错{    "error": {        "root_cause": [            {                "type": "invalid_type_name_exception",                "reason": "Document mapping type name can't start with '_', found: [_update]"            }        ],        "type": "invalid_type_name_exce

ruby-on-rails - Rails 迁移 : tried to change the type of column from string to integer

我使用railsgeneratemigrations命令在我的rails应用程序中创建了一个表。这是迁移文件:classCreateListings然后我想将纬度和经度存储为整数我试着跑:railsgeneratemigrationchangeColumnType该文件的内容是:classChangeColumnType我原以为列类型会发生变化,但是rake被中止并出现了以下错误消息。我想知道为什么这没有通过?我在我的应用程序中使用postgresql。rakedb:migrate==ChangeColumnType:migrating=========================

使用 Ubuntu 的 Ruby gem 权限被拒绝/var/lib/gems

我正在尝试使用Gem安装Rails并从终端执行以下操作:sudoapt-getinstallruby-fullbuild-essentialsudoapt-getinstallrubygemsexportPATH=/var/lib/gems/1.8/bin:$PATHgeminstallrails然后我收到以下消息:ERROR:Whileexecutinggem...(Errno:EACCES)Permissiondenied-/var/lib/gems我已按照UbuntuHelpGuide中的说明进行操作&我正在使用OracleVMVirtualBox在Windows7下运行Ubun

ruby-on-rails - Rails 3.1 中的 Rails.cache 错误 - TypeError : can't dump hash with default proc

我在3.1.0.rc4(ruby1.9.2p180(2011-02-18修订版30909)[x86_64-darwin10])上遇到Rails.cache方法问题。该代码在2.3.12(ruby1.8.7(2011-02-18补丁级别334)[i686-linux],MBARI0x8770,RubyEnterpriseEdition2011.03)上的同一应用程序中运行良好,但在升级后开始返回错误。我还没弄明白为什么。当尝试缓存具有多个作用域的对象时似乎会发生错误。此外,无论有多少范围,使用lambda的任何范围都会失败。我曾因这些模式而失败:Rails.cache.fetch("ke

ruby - Ruby 中的 class() 与 type()

Ruby中的类方法和类型方法有什么区别?我注意到type可以找到某些类的类型,但不能找到其他类的类型。 最佳答案 主要区别在于Object#type已弃用。来自对象#type的RDoc:DeprecatedsynonymforObject#class.这就是你应该使用Object#class的原因:Returnstheclassofobj,nowpreferredoverObject#type,asanobject‘stypeinRubyisonlylooselytiedtothatobject‘sclass.Thismethodm