Hi there. I''m just learning so bear with me. I have a column in my database for date_created and it shows in the view as Wed Nov 28 18:05:00 -0600 2007. I don''t really want it to display like that so is there a way to change how that date is formated in the view but not changed in the database? The code I have looks like this: <span id="created_on"><%= e.date_created %></span> Also in the _form.rhtml for editing entries, scaffolding builds this: <%= datetime_select ''entry'', ''date_created'' %> Is there anyway to have that not show but still put the time created in the database? If I remove the Sorry, totally nuby question here I''m sure. I may be hounding you guys again in the near future. Better to ask questions early and often. Thanks so much in advance to anyone who can shed a little light on this. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 30 Nov 2007, at 12:48, wsakundi wrote:> > Hi there. I''m just learning so bear with me. I have a column in my > database for date_created and it shows in the view as Wed Nov 28 > 18:05:00 -0600 2007. I don''t really want it to display like that so is > there a way to change how that date is formated in the view but not > changed in the database? The code I have looks like this: > > <span id="created_on"><%= e.date_created %></span>Sure, use strftime. Fred --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
This should be more useful to you: http://railscasts.com/episodes/31 On Nov 30, 7:48 am, wsakundi <w...-K/KL6SRTkijB5dNunts5jw@public.gmane.org> wrote:> Hi there. I''m just learning so bear with me. I have a column in my > database for date_created and it shows in the view as Wed Nov 28 > 18:05:00 -0600 2007. I don''t really want it to display like that so is > there a way to change how that date is formated in the view but not > changed in the database? The code I have looks like this: > > <span id="created_on"><%= e.date_created %></span> > > Also in the _form.rhtml for editing entries, scaffolding builds this: > > <%= datetime_select ''entry'', ''date_created'' %> > > Is there anyway to have that not show but still put the time created > in the database? If I remove the > > Sorry, totally nuby question here I''m sure. I may be hounding you guys > again in the near future. Better to ask questions early and often. > Thanks so much in advance to anyone who can shed a little light on > this.--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks so much. I should have checked there first. I haven''t gotten around to watching any of those yet which, I guess, I really should. Those and my bloody PeepCode downloads. Anyway, thanks again for pointing me in the right direction. I''d heard there was a supportive community for Rails and there''s the proof! On Nov 30, 8:08 am, ebrad <nisguy_...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> This should be more useful to you:http://railscasts.com/episodes/31--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
wsakundi wrote:> Hi there. I''m just learning so bear with me. I have a column in my > database for date_created and it shows in the view as Wed Nov 28 > 18:05:00 -0600 2007. I don''t really want it to display like that so is > there a way to change how that date is formated in the view but not > changed in the database? The code I have looks like this: > > <span id="created_on"><%= e.date_created %></span> >Basically, you can use strftime to change it to look like anything that suits you. Look it up in the Ruby API. it will be something like e.date_created.strftime("%d-%m-%Y") will give you something like 02-12-2007.> Also in the _form.rhtml for editing entries, scaffolding builds this: > > <%= datetime_select ''entry'', ''date_created'' %> > > Is there anyway to have that not show but still put the time created > in the database? If I remove the >Scaffold automatically creates the field for created_on in the form. You can delete it from the form. The user doesn''t need to enter a date for it. Rails will automatically insert the created_on datetime when the record is saved.> Sorry, totally nuby question here I''m sure. I may be hounding you guys > again in the near future. Better to ask questions early and often. > Thanks so much in advance to anyone who can shed a little light on > thisWelcome aboard! Cheers, Mohit. 12/2/2007 | 1:25 AM. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks. I''ve tried removing datetime_select but it won''t put the time into the table and then breaks because it''s returning a value of nil when I want that date to display in my list of entries. I thought that I could just put Time.now in there but, nope. That shows the time but doesn''t put it into the database. I guess I have more reading to do. Is that something I would fix in the Controller? or should I be correcting that (somehow) in my view? On Dec 1, 11:25 am, Mohit Sindhwani <mo_m...-RxrYI66vbj0AvxtiuMwx3w@public.gmane.org> wrote:> wsakundi wrote: > > Hi there. I''m just learning so bear with me. I have a column in my > > database for date_created and it shows in the view as Wed Nov 28 > > 18:05:00 -0600 2007. I don''t really want it to display like that so is > > there a way to change how that date is formated in the view but not > > changed in the database? The code I have looks like this: > > > <span id="created_on"><%= e.date_created %></span> > > Basically, you can use strftime to change it to look like anything that > suits you. Look it up in the Ruby API. > it will be something like e.date_created.strftime("%d-%m-%Y") will give > you something like 02-12-2007. > > > Also in the _form.rhtml for editing entries, scaffolding builds this: > > > <%= datetime_select ''entry'', ''date_created'' %> > > > Is there anyway to have that not show but still put the time created > > in the database? If I remove the > > Scaffold automatically creates the field for created_on in the form. > You can delete it from the form. The user doesn''t need to enter a date > for it. Rails will automatically insert the created_on datetime when > the record is saved. > > > Sorry, totally nuby question here I''m sure. I may be hounding you guys > > again in the near future. Better to ask questions early and often. > > Thanks so much in advance to anyone who can shed a little light on > > this > > Welcome aboard! > > Cheers, > Mohit. > 12/2/2007 | 1:25 AM.--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Dec 1, 2007, at 2:45 PM, wsakundi wrote:> > Thanks. I''ve tried removing datetime_select but it won''t put the time > into the table and then breaks because it''s returning a value of nil > when I want that date to display in my list of entries. I thought that > I could just put Time.now in there but, nope. That shows the time but > doesn''t put it into the database. I guess I have more reading to do. > Is that something I would fix in the Controller? or should I be > correcting that (somehow) in my view?Maybe I''m missing something in this question, but wouldn''t: <%= e.date_created.to_formatted_s(:short) %> do the trick? --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Put this in your config/environment.rb file at the bottom: ActiveSupport::CoreExtensions::Date::Conversions::DATE_FORMATS.update(:default => ''%m-%d-%Y'') ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.update(:default => ''%m-%d-%Y'') This will format ALL displayed time and date formats on your site to appear as 12-24-2007 format, so you only have to do e.date_created --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
If your column name is date_created, rails won''t automatically populate it with the time. If you want rails to create it for you, you should rename it to created_at, or created_on. If you don''t want to rename it you can modify your create action in the controller with something like this: def create @entry = Entry.new(params[:entry]) @entry.date_created = Time.now if @entry.save....bla bla bla ...bla bla end There may be a better way, like putting it in your model. Maybe someone else can chime in. On Dec 1, 5:45 pm, wsakundi <w...-K/KL6SRTkijB5dNunts5jw@public.gmane.org> wrote:> Thanks. I''ve tried removing datetime_select but it won''t put the time > into the table and then breaks because it''s returning a value of nil > when I want that date to display in my list of entries. I thought that > I could just put Time.now in there but, nope. That shows the time but > doesn''t put it into the database. I guess I have more reading to do. > Is that something I would fix in the Controller? or should I be > correcting that (somehow) in my view? > > On Dec 1, 11:25 am, Mohit Sindhwani <mo_m...-RxrYI66vbj0AvxtiuMwx3w@public.gmane.org> wrote: > > > wsakundi wrote: > > > Hi there. I''m just learning so bear with me. I have a column in my > > > database for date_created and it shows in the view as Wed Nov 28 > > > 18:05:00 -0600 2007. I don''t really want it to display like that so is > > > there a way to change how that date is formated in the view but not > > > changed in the database? The code I have looks like this: > > > > <span id="created_on"><%= e.date_created %></span> > > > Basically, you can use strftime to change it to look like anything that > > suits you. Look it up in the Ruby API. > > it will be something like e.date_created.strftime("%d-%m-%Y") will give > > you something like 02-12-2007. > > > > Also in the _form.rhtml for editing entries, scaffolding builds this: > > > > <%= datetime_select ''entry'', ''date_created'' %> > > > > Is there anyway to have that not show but still put the time created > > > in the database? If I remove the > > > Scaffold automatically creates the field for created_on in the form. > > You can delete it from the form. The user doesn''t need to enter a date > > for it. Rails will automatically insert the created_on datetime when > > the record is saved. > > > > Sorry, totally nuby question here I''m sure. I may be hounding you guys > > > again in the near future. Better to ask questions early and often. > > > Thanks so much in advance to anyone who can shed a little light on > > > this > > > Welcome aboard! > > > Cheers, > > Mohit. > > 12/2/2007 | 1:25 AM.--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Harmon wrote:> Put this in your config/environment.rb file at the bottom: > > > ActiveSupport::CoreExtensions::Date::Conversions::DATE_FORMATS.update(:default > => ''%m-%d-%Y'') > ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.update(:default > => ''%m-%d-%Y'') > > This will format ALL displayed time and date formats on your site to > appear as 12-24-2007 format, so you only have to do > > e.date_createdNot sure if this bug still exists, but doing this used to hose MySQL date columns. It would attempt to save the dates in the new format and mysql might not recognize it and instead populate the field with null. I don''t recommend altering the default format for this reason. -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Dec 12, 2007, at 11:12 PM, Kevin Olbrich wrote:> Harmon wrote: >> Put this in your config/environment.rb file at the bottom: >> >> ActiveSupport >> ::CoreExtensions::Date::Conversions::DATE_FORMATS.update(:default >> => ''%m-%d-%Y'') >> ActiveSupport >> ::CoreExtensions::Time::Conversions::DATE_FORMATS.update(:default >> => ''%m-%d-%Y'') >> >> This will format ALL displayed time and date formats on your site to >> appear as 12-24-2007 format, so you only have to do >> >> e.date_created > > Not sure if this bug still exists, but doing this used to hose MySQL > date columns. It would attempt to save the dates in the new format > and > mysql might not recognize it and instead populate the field with null. > > > I don''t recommend altering the default format for this reason.ActiveRecord should be using the :db format rather than the :default when making date strings to be consumed by the database. -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---