date localization

Hi,

I have a model with start_date and end_date and a helper:

def period
  "#{start_date} - #{end_date}"
end

in my view I have:

<%= f.collection_select :schedule_id,
@convention.schedules, :id, :period, {:selected => @schedule.id} %>

How can I show :period localized, as <%=l ... won't work.

Regards
Arwed

Hi,

I have a model with start_date and end_date and a helper:

def period
"#{start_date} - #{end_date}"

If you want the dates to appear as localised strings you must do it
here. Formatting them as appropriate as you build the string. If I
understand the question correctly.

Colin

Hi Colin,

thanks for your reply.

I defined my date formats in /config/locales/de.yml but I don't know
how to format my dates in my model. In view I can do <%=l
@schedule.start_date %>.

Can you tell me how I can do that with #{start_date}? The format I
need is dd.mm.yyy

Regards
Arwed

Hi Colin,

thanks for your reply.

I defined my date formats in /config/locales/de.yml but I don't know
how to format my dates in my model. In view I can do <%=l
@schedule.start_date %>.

Can you tell me how I can do that with #{start_date}? The format I
need is dd.mm.yyy

Have you tried #{l start_date}
The #{ } syntax in a double quoted string just says drop into ruby and
work out the expression between the braces.
Alternatively if you always want the same format you can use
#{start_date.strftime(some parameters to format it the way you want)}

Colin

Hi Colin,

I tried #{l start_date}, but I doesn't work.

I was hoping there was a way to use "l" in some way in my model. With
strftime it works.

Thanks for your help

Regards
Arwed

Hi Colin,

I tried #{l start_date}, but I doesn't work.

I was hoping there was a way to use "l" in some way in my model. With
strftime it works.

Possibly l is only available in views. In which case you would have
to put the period method that uses "#{l @start-date} - #{l end-date}}"
in the view helper.

Colin