Question

I have some Ruby variables that I am calling from my views that look like...

 {{ registration.orientation.class_date }}

This works fine, however I would like to format the date so its like...

 {{ registration.orientation.class_date.to_date.strftime('%A, %B %d') }}

This works find in the console...

irb(main):015:0> r.orientation.class_date.to_date.strftime('%A, %B %d')
=> "Friday, February 14"

When I put this in the view I get this error...

 Mustache::Parser::SyntaxError in Registrations#create

Showing /home/johnmlocklear/railsApps/nso/app/views/registrations/scheduling_text.html.erb where line #1 raised:

Unclosed tag
  Line 1
...
Extracted source (around line #1):

1: <%= Mustache.render(Page.find_by_name("Scheduling Text").content, {:registration => @registration }).html_safe %>

Ideas on whats going on here?

Was it helpful?

Solution

Calling methods with arguments violates the logic-less-ness of Mustache. Instead, you'd want to define a method on your orientation object (or on your view) that returns the formatted date:

def formatted_class_date
  class_date.to_date.strftime('%A, %B %d')
end

 

{{ registration.orientation.formatted_class_date }}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top