Mo.*_*Mo. 7 ruby ruby-on-rails
text_field_tag如果params [:date]的参数为空,我希望我将当前日期作为默认值,这里是我的代码:
<%= text_field_tag :end, params[:end] %>
Run Code Online (Sandbox Code Playgroud)
我想要像这样的东西: <%= text_field_tag :end, if params[:end] then use this value else show current date %>
谢谢
Abo*_*uby 15
您只需使用"或"运算符即可.如果params [:end]为空,它将使用Time.now.
<%= text_field_tag :end, (params[:end] or Time.now) %>
Run Code Online (Sandbox Code Playgroud)