简体   繁体   English

Rails NoMethodError(Time:Class的未定义方法“ something”):不太重要的错误

[英]Rails NoMethodError (undefined method `something ' for Time:Class): not so trivial error

class Email < ActiveRecord::Base
  # some code
  after_create :send_verification_email

  def send_verification_email
    puts 'edit 1', Time.now # it prints the actual date
    user_is_new = Time.now - user.created_at < 30 # This line pops an error
    unless verified || user_is_new # less than 30 seconds
      #some other code

I get an error at user_is_new=... 我在user_is_new =处收到错误

NoMethodError (undefined method `now ' for Time:Class):

WHY this error pops? 为什么会出现此错误?

I have already test in rails console and works fine, but in a request crash 我已经在Rails控制台中进行了测试,并且工作正常,但出现请求崩溃


Solution

Remove (replace) the (non-ascii?)space near the minus 删除(替换)负号附近的(非ASCII?)空间

user_is_new = Time.now-user.created_at < 30
NoMethodError (undefined method `now ' for Time:Class):

It says now not now or as in any other case, where the method can't be found. 它说, now不是now或在任何其他情况下,如果无法找到方法。 Try deleting the space right after the now method name. 尝试立即删除now方法名称后面的空格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM