获取“未定义的方法”错误或“没有这样的文件来加载错误”尝试使用 validates_timeiness gem

发布于 2024-12-04 10:27:13 字数 543 浏览 0 评论 0 原文

我正在尝试使用 validates_timeiness gem 并按照文档中的安装说明进行操作: https://github.com/adzap /validates_timeiness

gem 'validates_timeiness', '3.0.2' 捆绑安装 ruby-on-rails - Rails生成validates_timeiness:安装

然后我能够成功添加rspec测试并让它们通过使用gem中的validates_datetime功能

但是,当我在浏览器中转到我的新视图时,我收到错误:

未定义的方法'validates_datetime' #

我还尝试在模型文件顶部添加 require 'validates_timeiness',然后在控制器文件顶部添加。在这些情况下,我收到错误:“没有要加载的文件 - validates_timeiness

任何帮助将不胜感激,一直在尝试进行广泛的谷歌搜索。

I'm trying to use the validates_timeliness gem and followed the install instructions in the documentation: https://github.com/adzap/validates_timeliness

gem 'validates_timeliness', '3.0.2'
bundle install
rails generate validates_timeliness:install

I was then able to successfully add rspec tests and get them to pass using the validates_datetime feature from the gem

However, when I go to my new view in a browser, I get the error:

undefined method 'validates_datetime' for #

I also tried adding require 'validates_timeliness' at the top of the model file and then later at the top of the controller file. In those cases I get the error: 'no such file to load -- validates_timeliness

Any help would be much appreciated, have been trying to do extensive googling.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

悍妇囚夫 2024-12-11 10:27:13

正如说明中所述,它必须同时作为插件和gem安装。当单独作为 gem 安装时,似乎可以与 RSpec 配合使用,但不能在浏览器中使用。

我是如何解决的:

因此遇到此问题的其他人也可以尝试从 master 运行此代码以安装为插件:

rails plugin install git://github.com/adzap/validates_timeliness.git

adzap/validates_timeiness#installation

As noted in the instructions, it must be installed as both a plugin and a gem. When installed as a gem alone, seems to work fine with RSpec, but not in the browser.

How I fixed:

So anyone else that runs into this problem may also try running this code from master to install as plugin:

rails plugin install git://github.com/adzap/validates_timeliness.git

adzap/validates_timeliness#installation

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文