I''m trying to insert the selected values of the date_select object in the database but I''m getting nothing controller looks like this. def create @post = Post.new(params[:post]) if @post.save flash[:notice] = ''Post was successfully created.'' redirect_to :action => ''list'' else render :action => ''new'' end end this is the date_select field in my form <%= date_select :post, :birthdate, :order => [:month, :day, :year], :start_year => (Date.today - 99.years).strftime(''%Y'').to_i, :end_year => Date.today.strftime(''%Y'').to_i %> Am i doing something wrong? thanks -- Posted via http://www.ruby-forum.com/.
Frederick Cheung
2009-Apr-26 20:15 UTC
Re: problem inserting date_select values in the database
On Apr 26, 8:20 pm, Sam Ginko <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I''m trying to insert the selected values of the date_select object in > the database but I''m getting nothing >[snip]> > Am i doing something wrong?Not at first glance. Define nothing (date parameter is not in the request parameters at all, object does not save at all, object does save but the birthdate attribute is not set ...). If the browser is not submitting the date parameters at all, a common cause is invalid html. Fred> > thanks > -- > Posted viahttp://www.ruby-forum.com/.
It doe not insert anything into the database. I guess it''s what you describe as "save but the birthdate attribute is not set" Frederick Cheung wrote:> On Apr 26, 8:20�pm, Sam Ginko <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: >> I''m trying to insert the selected values of the date_select object in >> the database but I''m getting nothing >> > [snip] >> >> Am i doing something wrong? > > Not at first glance. Define nothing (date parameter is not in the > request parameters at all, object does not save at all, object does > save but the birthdate attribute is not set ...). If the browser is > not submitting the date parameters at all, a common cause is invalid > html. > > > Fred-- Posted via http://www.ruby-forum.com/.
James Byrne
2009-Apr-27 00:46 UTC
Re: problem inserting date_select values in the database
Sam Ginko wrote:> I''m trying to insert the selected values of the date_select object in > the database but I''m getting nothing > > controller looks like this. > def create > @post = Post.new(params[:post]) > if @post.save > flash[:notice] = ''Post was successfully created.'' > redirect_to :action => ''list'' > else > render :action => ''new'' > end > end >What does putting ''print params[:post].to_yaml'' just before the flash[:notice] show on the console? -- Posted via http://www.ruby-forum.com/.
Solved the problem. I was using attr_accessible and forgot to include the date_select field in it. Stupid of me. James Byrne wrote:> Sam Ginko wrote: >> I''m trying to insert the selected values of the date_select object in >> the database but I''m getting nothing >> >> controller looks like this. >> def create >> @post = Post.new(params[:post]) >> if @post.save >> flash[:notice] = ''Post was successfully created.'' >> redirect_to :action => ''list'' >> else >> render :action => ''new'' >> end >> end >> > > What does putting ''print params[:post].to_yaml'' just before the > flash[:notice] show on the console?-- Posted via http://www.ruby-forum.com/.
Solved the problem. I was using attr_accessible and forgot to include the date_select field in it. Stupid of me. thanks Frederick Cheung wrote:> On Apr 26, 8:20�pm, Sam Ginko <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: >> I''m trying to insert the selected values of the date_select object in >> the database but I''m getting nothing >> > [snip] >> >> Am i doing something wrong? > > Not at first glance. Define nothing (date parameter is not in the > request parameters at all, object does not save at all, object does > save but the birthdate attribute is not set ...). If the browser is > not submitting the date parameters at all, a common cause is invalid > html. > > > Fred-- Posted via http://www.ruby-forum.com/.