Hi, I am still very much a beginner at this - seems pretty neat though! I have a nice little comments form like so: <h3>Post a comment</h3> <%= form_tag :action => "comment", :id => @post %> Name:<br /><%= text_field "comment", "name" %><br /> Date:<br /><%= datetime_select "comment", "created_at" %><br /> Email: (won''t be displayed)<br /><%= text_field "comment", "email" %><br /> Website: (include http://)<br /><%= text_field "comment", "website" %><br /> Comment:<br /><%= text_area "comment", "body" %><br /> <%= submit_tag "Comment!" %> </form> Now, I don''t really want the user to be able to select a datetime, I''d rather that it was done serverside, but I''ve no idea how to do that. I toyed with replacing the datetime_select with a series of hidden_fields, but that doesn''t seem the right way, and anyway, I couldn''t work out how to get just the current year, just the day, just the minute etc. Also, the prepopulated datetime isn''t correct, probably due to me being in the UK and the server being in the US. I would rather have the datetime added in the controller I think, is this the correct way? def comment Post.find(params[:id]).comments.create(params[:comment]) flash[:notice] = "Added your comment." redirect_to :action => "show", :id => params[:id] end Perhaps it should go in there somewhere... Any ideas? Does anyone know of a good book/tutorial to get started on such issues? Thanks! -- 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 -~----------~----~----~----~------~----~------~--~---
Hi, could you explain what you''re trying to do because this will allow others to better assist you? It seems that you would like the datetime set automatically. If this is the case, then you want to remove the date selection from the form because the created_at field will automatically set by the rails framework. Please read section, "Magic Column Names", on page 319 of AWDwRv2. Good luck, -Conrad On Dec 23, 2007 1:24 PM, Richard Brashaw <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hi, > > I am still very much a beginner at this - seems pretty neat though! > > I have a nice little comments form like so: > > <h3>Post a comment</h3> > <%= form_tag :action => "comment", :id => @post %> > Name:<br /><%= text_field "comment", "name" %><br /> > Date:<br /><%= datetime_select "comment", "created_at" %><br /> > Email: (won''t be displayed)<br /><%= text_field "comment", "email" > %><br /> > Website: (include http://)<br /><%= text_field "comment", "website" > %><br /> > Comment:<br /><%= text_area "comment", "body" %><br /> > <%= submit_tag "Comment!" %> > </form> > > Now, I don''t really want the user to be able to select a datetime, I''d > rather that it was done serverside, but I''ve no idea how to do that. > > I toyed with replacing the datetime_select with a series of > hidden_fields, but that doesn''t seem the right way, and anyway, I > couldn''t work out how to get just the current year, just the day, just > the minute etc. Also, the prepopulated datetime isn''t correct, probably > due to me being in the UK and the server being in the US. > > I would rather have the datetime added in the controller I think, is > this the correct way? > > def comment > Post.find(params[:id]).comments.create(params[:comment]) > flash[:notice] = "Added your comment." > redirect_to :action => "show", :id => params[:id] > end > > Perhaps it should go in there somewhere... > > Any ideas? Does anyone know of a good book/tutorial to get started on > such issues? > > Thanks! > -- > 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 -~----------~----~----~----~------~----~------~--~---
Hi, I would highly recommend the following book: Agile Web Development with Rails 2 Edition You''ll want to complete Part II of this book and this will provide you with a good foundation to build from. Lastly, you can order the PDF and/or paperback from http://www.pragmaticprogrammer.com Good luck, -Conrad On Dec 23, 2007 1:40 PM, Conrad Taylor <conradwt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, could you explain what you''re trying to do because this will allow > others to better assist you? It seems that you would like the datetime set > automatically. If this is the case, then you want to remove the date > selection from the form because the created_at field will automatically set > by the rails framework. Please read section, "Magic Column Names", on page > 319 of AWDwRv2. > Good luck, > > -Conrad > > > On Dec 23, 2007 1:24 PM, Richard Brashaw <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: > > > > > Hi, > > > > I am still very much a beginner at this - seems pretty neat though! > > > > I have a nice little comments form like so: > > > > <h3>Post a comment</h3> > > <%= form_tag :action => "comment", :id => @post %> > > Name:<br /><%= text_field "comment", "name" %><br /> > > Date:<br /><%= datetime_select "comment", "created_at" %><br /> > > Email: (won''t be displayed)<br /><%= text_field "comment", "email" > > %><br /> > > Website: (include http://)<br /><%= text_field "comment", "website" > > %><br /> > > Comment:<br /><%= text_area "comment", "body" %><br /> > > <%= submit_tag "Comment!" %> > > </form> > > > > Now, I don''t really want the user to be able to select a datetime, I''d > > rather that it was done serverside, but I''ve no idea how to do that. > > > > I toyed with replacing the datetime_select with a series of > > hidden_fields, but that doesn''t seem the right way, and anyway, I > > couldn''t work out how to get just the current year, just the day, just > > the minute etc. Also, the prepopulated datetime isn''t correct, probably > > due to me being in the UK and the server being in the US. > > > > I would rather have the datetime added in the controller I think, is > > this the correct way? > > > > def comment > > Post.find(params[:id]).comments.create(params[:comment]) > > flash[:notice] = "Added your comment." > > redirect_to :action => "show", :id => params[:id] > > end > > > > Perhaps it should go in there somewhere... > > > > Any ideas? Does anyone know of a good book/tutorial to get started on > > such issues? > > > > Thanks! > > -- > > 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 -~----------~----~----~----~------~----~------~--~---
Don''t bother putting it in your form at all. You can do that server side. The model is the best place for it, you can use a before filter to execute all sorts of stuff, but in your case. In your post.rb model before_create :set_time def set_time self.created_at = Time.now end In saying all this however, check if rails 2.0 automatically fills this is for you. Try creating and saving a new record in the console, as I''m pretty sure that Rails will fill in this field automatically. over ''n out Cam --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Conrad Taylor wrote:> Hi, could you explain what you''re trying to do because this will allow > others to better assist you? It seems that you would like the datetime > set > automatically. If this is the case, then you want to remove the date > selection from the form because the created_at field will automatically > set > by the rails framework. Please read section, "Magic Column Names", on > page > 319 of AWDwRv2. > Good luck, > > -Conrad > > On Dec 23, 2007 1:24 PM, Richard Brashaw > <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>That was amazingly simple - RoR is awesome! I''ll read the book, sounds good. Thanks for everyones help! -- 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 -~----------~----~----~----~------~----~------~--~---