Forum: Ruby on Rails problem inserting date_select values in the database

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
2c49cd424ddb3b3c9cef6ef7f45c8534?d=identicon&s=25 Sam Ginko (ginkod)
on 2009-04-26 21:20
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
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-04-26 22:16
(Received via mailing list)
On Apr 26, 8:20 pm, Sam Ginko <rails-mailing-l...@andreas-s.net>
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
2c49cd424ddb3b3c9cef6ef7f45c8534?d=identicon&s=25 Sam Ginko (ginkod)
on 2009-04-26 22:50
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...@andreas-s.net>
> 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
171ea139761951336b844e708d1547ab?d=identicon&s=25 James Byrne (byrnejb)
on 2009-04-27 02:46
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?
2c49cd424ddb3b3c9cef6ef7f45c8534?d=identicon&s=25 Sam Ginko (ginkod)
on 2009-04-27 04:17
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?
2c49cd424ddb3b3c9cef6ef7f45c8534?d=identicon&s=25 Sam Ginko (ginkod)
on 2009-04-27 04:17
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...@andreas-s.net>
> 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
This topic is locked and can not be replied to.