I use the following code in my view: <%= collection_select(''datedata'', ''date'', @allDate, :id, :date) %> It''s show me the date of all entries in the database (Dropdown menu). Additional, I wrote a helper method "showDate" in the application_helper.rb! How can I use this method in the collection_select for every date entry? thanks for your anwser! -- Posted via http://www.ruby-forum.com/.
What is it that you''re trying to accomplish with your ''showDate'' method? On 8/17/06, M. R. <ribi@schwingerverband.ch> wrote:> > I use the following code in my view: > > <%= collection_select(''datedata'', ''date'', @allDate, :id, :date) %> > > It''s show me the date of all entries in the database (Dropdown menu). > Additional, I wrote a helper method "showDate" in the > application_helper.rb! How can I use this method in the > collection_select for every date entry? > > thanks for your anwser! > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- "Impossible is nothing." -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060817/942779b2/attachment-0001.html
Fran?ois Montel wrote:> What is it that you''re trying to accomplish with your ''showDate'' method?I would like to show the date in my favorite style. The following code is the used method: def showDate(d) d.strftime("%d.%m.%y") end I want to display the date in the collection with the method! -- Posted via http://www.ruby-forum.com/.
On 8/18/06, M. R. <ribi@schwingerverband.ch> wrote:> > Fran?ois Montel wrote: > > What is it that you''re trying to accomplish with your ''showDate'' method? > > I would like to show the date in my favorite style. The following code > is the used method: > > def showDate(d) > d.strftime("%d.%m.%y") > end > > I want to display the date in the collection with the method! >The first idea that comes to mind is to modify your collection_select call: <%= collection_select(''datedata'', ''date'', @allDate.collect{|d| showDate(d)}, :id, :date) %> But that''s a little ugly. You could modify your helper thusly: def showDate(d=Time.now) date_format = "%d.%m.%y" if Array === d d.collect {|date| date.strftime(date_format)} else d.strftime(date_format) end end This lets you pass the helper a Date object or an array of Dates, and get back what you''d expect. -- Jim Kane fastjames@gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060818/f506bf91/attachment.html