I recently started using jQuery and the Datepicker with an application of mine. with the help of http://railscasts.com/episodes/213-calendars I got the datepicker working on a text_field containing a date. Problem however is when we edit a model. Since a text_field shows the database value for a field by default, it displays the date as ''2011-05-24''. When we open te datepicker on this field it defaults to ''today'' since it cant read the current value of the field. Picking a date will display it in the format specified of datepicker, but saving is no problem. I guess Rails is smart enough to figure it out between the I18n. My question is, how can I make sure my date is displayed in the format I want it to be in the text_field of a form when editting. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
<html> <head> <meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type"> </head> <body bgcolor="#FFFFFF" text="#000000"> Hi,<br> <br> There are two places were you should do it:<br> - <b>Rails</b>: Best choice is <a href="http://guides.rubyonrails.org/i18n.html">I18N API</a>, summary:<br> 1. Get the locales you need from <a class="moz-txt-link-freetext" href="https://github.com/svenfuchs/rails-i18n/tree/master/rails/locale">https://github.com/svenfuchs/rails-i18n/tree/master/rails/locale</a><br> 2. Place them in "config\locales\"<br> 3. In "config\aplication.rb" uncomment the lines<br> <span style="color: #666666;"> # config.i18n.load_path += Dir[Rails.root.join(''my'', ''locales'', ''*.{rb,yml}'').to_s]</span><br style="color: #666666;"> <span style="color: #666666;"> # config.i18n.default_locale = :de</span><br> 4. Set your default language, example for Spanish <br> <span style="color: #666666;"> config.i18n.default_locale = :es </span><br> 5. Add an the file "nitializers\date_formats.rb" with the content<br> <span style="color: #666666;"> </span><span style="color: #666666;">Time::DATE_FORMATS[:default] = lambda { |time| I18n.l(time) }</span><br style="color: #666666;"> <span style="color: #666666;"> </span><span style="color: #666666;">Date::DATE_FORMATS[:default] = lambda { |date| I18n.l(date) }</span><br> 6. Restart the server.<br> - <b>Datepicker</b>: in the place where you call it add:<br> <font color="#666666"> </font><font color="#666666">$.timepicker.setDefaults($.timepicker.regional[''es'']);</font><br> <br> You might want to have different regional settings (included date and time formats) for each users, then the best solution is to place the regional variable in the users models (Examples in the I18N api).<br> <br> Just one last think, rails will not raise and error if the format is wrong, instead will save a nil value in the database.<br> <br> Greetings,<br> <br> El 30/09/2011 3:39, Tom Pett escribió: <blockquote cite="mid:dadca8b71f9e5c81f68ec7dad123448c-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org" type="cite"> <pre wrap="">I recently started using jQuery and the Datepicker with an application of mine. with the help of <a class="moz-txt-link-freetext" href="http://railscasts.com/episodes/213-calendars">http://railscasts.com/episodes/213-calendars</a> I got the datepicker working on a text_field containing a date. Problem however is when we edit a model. Since a text_field shows the database value for a field by default, it displays the date as ''2011-05-24''. When we open te datepicker on this field it defaults to ''today'' since it cant read the current value of the field. Picking a date will display it in the format specified of datepicker, but saving is no problem. I guess Rails is smart enough to figure it out between the I18n. My question is, how can I make sure my date is displayed in the format I want it to be in the text_field of a form when editting. </pre> </blockquote> <br> <pre class="moz-signature" cols="72">-- Miquel Cubel Escarré +34 699 73 22 46 <a class="moz-txt-link-abbreviated" href="mailto:mcubel-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org">mcubel-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org</a></pre> </body> </html> <p></p> -- <br /> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.<br /> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org<br /> To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org<br /> For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.<br />
Hi Tom, I had a similar task lately and the solution goes roughly like this: First you get the localization file from here: http://jquery-ui.googlecode.com/svn/trunk/ui/i18n/ You need to load this together with the other jQuery js like this: <%= javascript_include_tag ''jquery/jquery.ui.datepicker-de.js'' %> After that you can setup you form like this: <%= label :start_date, "Datum von:" %> <%= text_field_tag :start_date, Time.now.strftime(''%d.%m. %Y''), :autocomplete => "off", :class => "input_element" %> <%= label :end_date, "bis:" %> <%= text_field_tag :end_date, Time.now.strftime(''%d.%m. %Y''), :autocomplete => "off", :class => "input_element" %> <%= submit_tag :for, :value => t("buttons.search") %> <script> $.datepicker.setDefaults( $.datepicker.regional["de"] ); $.datepicker.setDefaults({showWeek: true, minDate: new Date(2011, 0, 1), maxDate: "today", showOtherMonths: true, selectOtherMonths: true }); $(''#start_date'').datepicker(); $(''#end_date'').datepicker(); </script> This worked for me (didn''t implement the Rails side on the server yet) On Sep 30, 3:39 am, Tom Pett <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I recently started using jQuery and the Datepicker with an application > of mine. > > with the help ofhttp://railscasts.com/episodes/213-calendarsI got the > datepicker working on a text_field containing a date. > > Problem however is when we edit a model. Since a text_field shows the > database value for a field by default, it displays the date as > ''2011-05-24''. When we open te datepicker on this field it defaults to > ''today'' since it cant read the current value of the field. > > Picking a date will display it in the format specified of datepicker, > but saving is no problem. I guess Rails is smart enough to figure it out > between the I18n. > > My question is, how can I make sure my date is displayed in the format I > want it to be in the text_field of a form when editting. > > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi Tom, I had a similar task lately and the solution goes roughly like this: First you get the localization file from here: http://jquery-ui.googlecode.com/svn/trunk/ui/i18n/ You need to load this together with the other jQuery js like this: <%= javascript_include_tag ''jquery/jquery.ui.datepicker-de.js'' %> After that you can setup you form like this: <%= label :start_date, "Datum von:" %> <%= text_field_tag :start_date, Time.now.strftime(''%d.%m. %Y''), :autocomplete => "off", :class => "input_element" %> <%= label :end_date, "bis:" %> <%= text_field_tag :end_date, Time.now.strftime(''%d.%m. %Y''), :autocomplete => "off", :class => "input_element" %> <%= submit_tag :for, :value => t("buttons.search") %> <script> $.datepicker.setDefaults( $.datepicker.regional["de"] ); $.datepicker.setDefaults({showWeek: true, minDate: new Date(2011, 0, 1), maxDate: "today", showOtherMonths: true, selectOtherMonths: true }); $(''#start_date'').datepicker(); $(''#end_date'').datepicker(); </script> This worked for me (didn''t implement the Rails side on the server yet) On Sep 30, 3:39 am, Tom Pett <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I recently started using jQuery and the Datepicker with an application > of mine. > > with the help ofhttp://railscasts.com/episodes/213-calendarsI got the > datepicker working on a text_field containing a date. > > Problem however is when we edit a model. Since a text_field shows the > database value for a field by default, it displays the date as > ''2011-05-24''. When we open te datepicker on this field it defaults to > ''today'' since it cant read the current value of the field. > > Picking a date will display it in the format specified of datepicker, > but saving is no problem. I guess Rails is smart enough to figure it out > between the I18n. > > My question is, how can I make sure my date is displayed in the format I > want it to be in the text_field of a form when editting. > > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi Tom, I had a similar task lately and the solution goes roughly like this: First you get the localization file from here: http://jquery-ui.googlecode.com/svn/trunk/ui/i18n/ You need to load this together with the other jQuery js like this: <%= javascript_include_tag ''jquery/jquery.ui.datepicker-de.js'' %> After that you can setup you form like this: <%= label :start_date, "Datum von:" %> <%= text_field_tag :start_date, Time.now.strftime(''%d.%m. %Y''), :autocomplete => "off", :class => "input_element" %> <%= label :end_date, "bis:" %> <%= text_field_tag :end_date, Time.now.strftime(''%d.%m. %Y''), :autocomplete => "off", :class => "input_element" %> <%= submit_tag :for, :value => t("buttons.search") %> <script> $.datepicker.setDefaults( $.datepicker.regional["de"] ); $.datepicker.setDefaults({showWeek: true, minDate: new Date(2011, 0, 1), maxDate: "today", showOtherMonths: true, selectOtherMonths: true }); $(''#start_date'').datepicker(); $(''#end_date'').datepicker(); </script> This worked for me (didn''t implement the Rails side on the server yet) On Sep 30, 3:39 am, Tom Pett <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I recently started using jQuery and the Datepicker with an application > of mine. > > with the help ofhttp://railscasts.com/episodes/213-calendarsI got the > datepicker working on a text_field containing a date. > > Problem however is when we edit a model. Since a text_field shows the > database value for a field by default, it displays the date as > ''2011-05-24''. When we open te datepicker on this field it defaults to > ''today'' since it cant read the current value of the field. > > Picking a date will display it in the format specified of datepicker, > but saving is no problem. I guess Rails is smart enough to figure it out > between the I18n. > > My question is, how can I make sure my date is displayed in the format I > want it to be in the text_field of a form when editting. > > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi Tom, I had a similar task lately and the solution goes roughly like this: First you get the localization file from here: http://jquery-ui.googlecode.com/svn/trunk/ui/i18n/ You need to load this together with the other jQuery js like this: <%= javascript_include_tag ''jquery/jquery.ui.datepicker-de.js'' %> After that you can setup you form like this: <%= label :start_date, "Datum von:" %> <%= text_field_tag :start_date, Time.now.strftime(''%d.%m.%Y''), :autocomplete => "off", :class => "input_element" %> <%= label :end_date, "bis:" %> <%= text_field_tag :end_date, Time.now.strftime(''%d.%m.%Y''), :autocomplete => "off", :class => "input_element" %> <%= submit_tag :for, :value => t("buttons.search") %> <script> $.datepicker.setDefaults( $.datepicker.regional["de"] ); $.datepicker.setDefaults({showWeek: true, minDate: new Date(2011, 0, 1), maxDate: "today", showOtherMonths: true, selectOtherMonths: true }); $(''#start_date'').datepicker(); $(''#end_date'').datepicker(); </script> This worked for me (didn''t implement the Rails side on the server yet) -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/x_BjKTFYljsJ. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi Tom, I had a similar task lately and the solution goes roughly like this: First you get the localization file from here: http://jquery-ui.googlecode.com/svn/trunk/ui/i18n/ You need to load this together with the other jQuery js like this: <%= javascript_include_tag ''jquery/jquery.ui.datepicker-de.js'' %> After that you can setup you form like this: <%= label :start_date, "Datum von:" %> <%= text_field_tag :start_date, Time.now.strftime(''%d.%m.%Y''), :autocomplete => "off" %> <%= label :end_date, "bis:" %> <%= text_field_tag :end_date, Time.now.strftime(''%d.%m.%Y''), :autocomplete => "off" %> <%= submit_tag :for, :value => t("buttons.search") %> <script> $.datepicker.setDefaults( $.datepicker.regional["de"] ); $.datepicker.setDefaults({showWeek: true, minDate: new Date(2011, 0, 1), maxDate: "today", showOtherMonths: true, selectOtherMonths: true }); $(''#start_date'').datepicker(); $(''#end_date'').datepicker(); </script> This worked for me (didn''t implement the Rails side on the server yet) -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/dqVWQzl9T0gJ. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.