Topic: Formatting non existing data [SOLVED]

I am using the same from for create and edit via a partial.
but i am formatting a time field on the exit but i am getting a error when i go to create


= f.text_field :start_time , {:class => 'medium-label-1 input small-margin-right', :value=> event.start_time.in_time_zone(current_user.account.timezone).try(:strftime ,'%l:%M %p %Z').to_s}

error
undefined method `in_time_zone' for nil:NilClass

Last edited by moiseszaragoza (2012-07-23 10:55:12)

Re: Formatting non existing data [SOLVED]

Try doing something like

- if event.start_time
            - start_time_val = event.start_time.in_time_zone(current_user.account.timezone).try(:strftime ,'%l:%M %p %Z').to_s
          - else
            - start_time_val = ''
          = f.text_field :start_time , {:class => 'medium-label-1 input small-margin-right', :value=> start_time_val}