草庐IT

validation_methods

全部标签

ruby-on-rails - validates_inclusion_of 在 Rails 4.1 中不再正常工作?

以下代码确保选择的time_zone在ActiveSupport::TimeZone.us_zones中的时区内:validates_inclusion_of:time_zone,in:ActiveSupport::TimeZone.zones_map(&:name)在Rails4.0中表现出色。刚刚升级到Rails4.1,我的索引页面上出现了这个错误(所以只是简单地查看模型):Anobjectwiththemethod#include?oraproc,lambdaorsymbolisrequired,andmustbesuppliedasthe:in(or:within)option

ruby-on-rails - rails : why is calling to_a on a string not valid in a rake task?

我正在尝试解密一组用于数据库迁移的密码。我有一些旧的Rails代码(实际上是一个Runner脚本)可以很好地解密它们。但是将相同的代码放入Rake任务会导致任务失败,并显示...未定义的方法`to_a'for"secretkey":String...为什么在字符串上调用to_a在Rake任务中无效,但在Runner脚本中却完全有效?require'openssl'KEY='secretkey'namespace:importdotask:users=>:environmentdodefdecrypt_password(pw)cipher=OpenSSL::Cipher::Cipher.

ruby-on-rails - `undefined method ` 查找 Assets ' for nil:NilClass`

我正在使用'rails'、'4.2.5'和wicked_pdfgem来生成和下载PDF,但是在Heroku上,它不包括使用的csswicked_pdf_stylesheet_link_tag标签。Heroku错误日志:ActionView::Template::Error(undefinedmethod'find_asset'fornil:NilClass)我是否遗漏了这里的任何配置? 最佳答案 要使其适用于开发和生产环境,请不要使用Rails.application.assets.find_asset(logical_file_p

ruby - irb 中的所有命令都给出 "NoMethodError: undefined method ` write' for nil :NilClass"

我正在尝试从IRB获取当前的ruby​​版本,但它给我这个错误:>>RUBY_VERSIONNoMethodError:undefinedmethod`write'fornil:NilClassfrom/usr/local/lib/ruby/1.9.1/irb.rb:311:in`printf'from/usr/local/lib/ruby/1.9.1/irb.rb:311:in`output_value'from/usr/local/lib/ruby/1.9.1/irb.rb:160:in`block(2levels)ineval_input'from/usr/local/lib/r

ruby 场 : documenting abstract methods implementations

我有一个典型的OO模式:一个基本抽象类(定义抽象方法)和几个以特定于类的方式实现这些抽象方法的类。我习惯于在抽象方法中只编写一次文档,然后它会自动传播到几个具体类(至少它在Javadoc、Scaladoc、Doxygen中按以下方式工作),即我不需要重复所有具体类中的相同描述。但是,我找不到如何在YARD中进行此类传播。我试过,例如:#Somedescriptionofabstractclass.#@abstractclassAbstractClass#Somemethoddescription.#@return[Symbol]somereturndescription#@abstra

ruby-on-rails - vim/macvim : locate where a method/symbol is defined

我的大部分Ruby+RubyonRails开发都使用macvim/vim。目前是否有一种方法可以跳转到项目中定义方法的位置,即使它与调用它的位置不在同一个文件中?与语言无关的方式或特定于Ruby/Rails的方式均可。 最佳答案 我推荐使用ctags插件,BryanLiles制作了一个很好的截屏视频,介绍如何在Rails开发中使用它。http://smartic.us/2009/04/05/using-ctags-in-vim/来自他的页面:不那么完整的备忘单:^]–查找标签^T——倒退:tags–显示你去过的地方:tag–进入你的

ruby-on-rails - 弃用警告 : Dangerous query method (method whose arguments are used as raw SQL) called with non-attribute argument(s)

我将我的Rails5.1.4应用更新到了5.2.0。我的一个模型中有以下范围:scope:by_category,lambda{|category_slug|category_ids=Category.find_by(slug:category_slug)&.subtree_idswhere(category_id:category_ids)}由于该范围,Rails返回以下错误:DEPRECATIONWARNING:Dangerousquerymethod(methodwhoseargumentsareusedasrawSQL)calledwithnon-attributeargume

ruby-on-rails - rails : accessing field value from model method

刚开始学习Rails(三)。我正在努力寻找如何做一些可能完全微不足道的事情:从该模型的方法内部访问模型实例字段的值。以我为例:defformal_name@title+""+@forename+""+@surnameend所有三个@properties(它们都是数据库中表上的字段)都返回nil。他们不应该。令人难以置信的是,http://guides.rails.info/并未讨论如何访问字段,google什么也找不到。顺便说一句,我来自Django,这里的东西很明显。 最佳答案 @语法用于实例变量,这些实例变量(例如)在Contr

Ruby 2.4.1 Dir.children( dirname ) 为 Dir :Class"返回 "undefined method ` children'

我是Ruby的新手,正在尝试学习它。我使用的是最新的Ruby版本(2.4.1)和交互式RubyShell。我在Dir类中遇到过children方法。我试过这个例子fromthedocumentation:Dir.children("testdir")#=>["config.h","main.rb"]但它似乎不起作用,因为我收到以下消息:undefinedmethod`children'forDir:Class我错过了什么? 最佳答案 这似乎是某种文档困惑。Dir.children方法是在Feature#11302中引入的进入Ruby

ruby - undefined symbol : SSLv3_method - . ../openssl.so 与 Ruby 和 ArchLinux

ArchLinux最近的OpenSSL更新破坏了Ruby,因为后者依赖于前者支持的SSLv3。使用OpenSSL的Ruby代码会在它们终止并出现如下错误时揭示问题:openssl.so:undefinedsymbol:SSLv3_method-.../openssl.so(LoadError)我将多个版本的Ruby与RVM一起使用这个问题适用于所有人。我遇到问题的OpenSSL版本是1.0.2h,但我相信它是在1.0.2g中引入的。版本1.0.2f工作正常。如何解决兼容性问题(不降级OpenSSL)? 最佳答案 问题是由于ArchL