Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Text_field_tag default value if params are empty?

I want my text_field_tag to have the current date as a default value if the params for params[:date] is empty, here is my code at the moment:

<%= text_field_tag :end, params[:end]  %>

i want somthing like: <%= text_field_tag :end, if params[:end] then use this value else show current date %>

thank you

like image 860
Mo. Avatar asked Aug 23 '10 22:08

Mo.


1 Answers

You can simply use the "or" operator. If params[:end] is empty, it'll use Time.now.

<%= text_field_tag :end, (params[:end] or Time.now)  %>
like image 176
AboutRuby Avatar answered Oct 30 '22 11:10

AboutRuby