I18n month translation

916 views Asked by At

I'm trying to translate a month with I18n and I'm getting this error:

undefined method `strftime' for "2015-05-18":String

Code:

# controller
@previous_month = I18n.l(Date.today - (1%12).months)

# view
@previous_month.strftime('%B')

How can I solve this error?

2

There are 2 answers

0
AbM On BEST ANSWER

controller:

@previous_month = Date.today - (1%12).months

view:

I18n.l @previous_month, :format => "%B"
0
AlexLarra On

You can not do it that with a string but yes with date

@previous_month = Date.today - (1%12).months

@previous_month.strftime('%B')