Hi having trouble saving dates in my form i have the following in the view <%= date_select("details", "open_date") %> and i have @exhibition.open_date = params[:details][:open_date] and then @exhibition.save All the other values form (not seen here) get saved but not the dates. What am i doing wrong ? -- 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 -~----------~----~----~----~------~----~------~--~---
Model and schema please... --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
askegg wrote:> Model and schema please...# == Schema Information # Schema version: 57 # # Table name: exhibitions # # id :integer(11) not null, primary key # name :string(255) # subtitle :string(255) # short_description :string(255) # description :string(255) # curator :string(255) # artists :string(255) # url :string(255) # image :string(255) default(/exhibition/image/1_0.gif) # catalogue :string(255) # admission_price :text # open_date :date # close_date :date # user_id :integer(11) # gallery_id :integer(11) class Exhibition < ActiveRecord::Base has_one :advertisement belongs_to :user belongs_to :image belongs_to :gallery belongs_to :listing_status has_and_belongs_to_many :organisations has_and_belongs_to_many :artists has_and_belongs_to_many :curators has_and_belongs_to_many :festivals has_and_belongs_to_many :tags has_one :feature_exhibition has_many :weeks validates_presence_of :name, :short_description, :subtitle, :on => :create #file_column :image def self.find_exhibitions_currently_on find(:all, :conditions => "(open_date < now()) && (close_date > now())", :order => "close_date desc" ) end def self.find_exhibitions_closed find(:all, :conditions => "close_date < now()", :order => "close_date") end def self.find_exhibitions_coming_up find(:all, :conditions => "open_date > now()", :order => "open_date") end end -- 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 -~----------~----~----~----~------~----~------~--~---
??? Damn. Looks fine to me. Anything in the logs? Drop <%= debug(params) %> into the view and see whats there. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
askegg wrote:> ??? Damn. Looks fine to me. > > Anything in the logs? > > Drop <%= debug(params) %> into the view and see whats there.so its not something i am doing wrong in the code then.... humm anyone else with any ideas here? -- 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 12/14/06, Guest <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > askegg wrote: > > ??? Damn. Looks fine to me. > > > > Anything in the logs? > > > > Drop <%= debug(params) %> into the view and see whats there. > > so its not something i am doing wrong in the code then.... humm anyone > else with any ideas here?Did you put <%= debug(params) %> into the view like askegg said? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Daniel ----- wrote:> On 12/14/06, Guest <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: >> else with any ideas here? > Did you put > > <%= debug(params) %> into the view like askegg said?what view? The view of the page after the insert? Of the view of the page where the user selects the date? -- 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 -~----------~----~----~----~------~----~------~--~---
Guest wrote:> Daniel ----- wrote: >> On 12/14/06, Guest <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: >>> else with any ideas here? >> Did you put >> >> <%= debug(params) %> into the view like askegg said? > > what view? > > The view of the page after the insert? > Of the view of the page where the user selects the date?here is the dump of after... --- !map:HashWithIndifferentAccess commit: Continue To Step 2 of 3... details: !map:HashWithIndifferentAccess name: This test isfree: "no" admission_price: "" open_date(1i): "2006" license: "1" close_date(1i): "2006" open_date(2i): "12" close_date(2i): "12" short_description: yes yes yes it is open_date(3i): "14" url: http:// close_date(3i): "14" contributors: "" subtitle: this is a test description: "" year: "2006" copywho: "" action: extradetails controller: listing/add -- 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 -~----------~----~----~----~------~----~------~--~---
Stewart wrote:> @exhibition.open_date = params[:details][:open_date]My intuition tells me that wont work because params[:details][:open_date] is likely a hash, not a date object. I''m not entirely sure how (or where) rails does the magic conversion on the way in. Note it''s only my intuituition, with nothing solid to back that up :-) A. -- 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 -~----------~----~----~----~------~----~------~--~---
I think Alan is right. Rails is expected a date, but you are passing it an array. Use date_select in your form instead of an array of values. (http://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html#M000469) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
askegg wrote:> I think Alan is right. Rails is expected a date, but you are passing > it an array. > > Use date_select in your form instead of an array of values. > (http://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html#M000469)I think i already am... here is my code anyway. <p> <label for="details_open_date"> Date the exhibition opens: </label> </p> <p> <%= date_select("details", "open_date") %> <span style="color:red"> *Required </span> </p> <p> <label for="details_close_date"> Date the exhibition closes: </label> </p> <p> <%= date_select("details", "close_date") %> <span style="color:red"> *Required </span> </p> am i used date_select in the correct way? -- 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 -~----------~----~----~----~------~----~------~--~---
That is the correct usage, but your controller is trying to pull the date submitted apart and force it into the database. Since the date fields are named with the database field name you can just use: Exhibition.create(params[:details]) instead of: @exhibition.open_date = params[:details][:open_date] @exhibition.save If you want some error checking, you might want to try something like: @exhibition = Exhibition.new(params[:details]) if @exhibition.save flash[:notice] = "Exhibition created" redirect_to :action => :index and return On Dec 19, 3:03 pm, Stewart <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> askegg wrote: > > I think Alan is right. Rails is expected a date, but you are passing > > it an array. > > > Use date_select in your form instead of an array of values. > > (http://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html...)I think i already am... > > here is my code anyway. > > <p> > <label for="details_open_date"> > Date the exhibition opens: > </label> > </p> > <p> > <%= date_select("details", "open_date") %> > <span style="color:red"> > *Required > </span> > </p> > <p> > <label for="details_close_date"> > Date the exhibition closes: > </label> > </p> > <p> > <%= date_select("details", "close_date") %> > <span style="color:red"> > *Required > </span> > </p> > > am i used date_select in the correct way? > > -- > 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-/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 -~----------~----~----~----~------~----~------~--~---
askegg wrote:> That is the correct usage, but your controller is trying to pull the > date submitted apart and force it into the database. > Since the date fields are named with the database field name you can > just use: > > Exhibition.create(params[:details]) > > instead of: > > @exhibition.open_date = params[:details][:open_date] > @exhibition.save > > If you want some error checking, you might want to try something like: > > @exhibition = Exhibition.new(params[:details]) > if @exhibition.save > flash[:notice] = "Exhibition created" > redirect_to :action => :index and returnThanks askegg that was it. Rails needs you to send all the data at once and not set it 1 by 1 like i was. I was not fully understanding how that all worked. Now i do and i cant see myself making the same mistake again. Thanks for all your help with the posts. -- 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 -~----------~----~----~----~------~----~------~--~---