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
2009/9/20 arwed <af-0WR/Tm5k6cQ@public.gmane.org>:> > 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> 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 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 On 20 Sep., 21:46, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> 2009/9/20 arwed <a...-0WR/Tm5k6cQ@public.gmane.org>: > > > > > 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 > > > 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 > >
2009/9/20 arwed <af-0WR/Tm5k6cQ@public.gmane.org>:> > 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.yyyHave 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> > Regards > Arwed > > > On 20 Sep., 21:46, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> 2009/9/20 arwed <a...-0WR/Tm5k6cQ@public.gmane.org>: >> >> >> >> > 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 >> >> > 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 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 On 20 Sep., 22:29, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> 2009/9/20 arwed <a...-0WR/Tm5k6cQ@public.gmane.org>: > > > > > 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 > > > > > Regards > > Arwed > > > On 20 Sep., 21:46, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > >> 2009/9/20 arwed <a...-0WR/Tm5k6cQ@public.gmane.org>: > > >> > 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 > > >> > 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 > >
2009/9/21 arwed <af-0WR/Tm5k6cQ@public.gmane.org>:> > 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> > Thanks for your help > > Regards > Arwed > > On 20 Sep., 22:29, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> 2009/9/20 arwed <a...-0WR/Tm5k6cQ@public.gmane.org>: >> >> >> >> > 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 >> >> >> >> > Regards >> > Arwed >> >> > On 20 Sep., 21:46, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> >> 2009/9/20 arwed <a...-0WR/Tm5k6cQ@public.gmane.org>: >> >> >> > 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 >> >> >> > 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 >> >> > > >