0

I need to specify the format of a date object I'm passing as a symbol in a form in erb.

With the following two lines:

This line causes an error:

<%= e.text_field :from_date, value: event.from_date.to_s, {class: "eventStartDate"} %>

This line does not:

<%= e.text_field :from_date, {class: "eventStartDate"} %>

I believe the first line will display my date correctly, as evidenced by this thread: Rails 3 Date format in forms

Why is this version giving me an error?

The error:

rails server

ERROR: compiling _app_views_planners__edit_event_html_erb___606087105846834961_70190839785020 RAISED ~/app/views/planners/_edit_event.html.erb:14: syntax error, unexpected ')', expecting tASSOC
..._s, {class: "eventStartDate"} );@output_buffer.safe_concat('...
...                               ^
~/app/views/planners/_edit_event.html.erb:33: syntax error, unexpected keyword_end, expecting ')'
'); end ;@output_buffer.to_s
       ^

Line 14 of the partial _edit_event_html_erb

<%= e.text_field :from_date, value: event.from_date.to_s, {class: "eventStartDate"} %>&ndash;<%= e.text_field :to_date, {class: "eventEndDate"} %>

Line 33 is the end of the file. <% end %>

Community
  • 1
  • 1
Eric Baldwin
  • 3,341
  • 10
  • 31
  • 71

1 Answers1

0

Remove the {} of the class. value and class should be in same hash.

<%= e.text_field :from_date, value: event.from_date.to_s, class: "eventStartDate" %>
xdazz
  • 158,678
  • 38
  • 247
  • 274