TimeDate方法检查返回nil

时间:2018-01-30 15:06:28

标签: ruby-on-rails

我试图从rails方法返回true / false,但它一直返回nil。

不确定我哪里出错了。

def method_name?
  DateTime.now < DateTime.new(2018, 5, 14, 23, 59, 59)
end

然后我通过

调用它
<% if @method_name %>

  Show this

<% else %>

  Show that

<% end %>

1 个答案:

答案 0 :(得分:6)

我认为method_name?是帮手。请改变:

<% if @method_name %>

<% if method_name? %>

调用@method_name表示访问实例变量,该变量不存在,以便返回nil

相关问题