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.
Sam G. (Guest)
on 2009-04-26 23: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
Frederick C. (Guest)
on 2009-04-27 00:16
(Received via mailing list)
On Apr 26, 8:20 pm, Sam G. <removed_email_address@domain.invalid>
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
Sam G. (Guest)
on 2009-04-27 00: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 C. wrote:
> On Apr 26, 8:20�pm, Sam G. <removed_email_address@domain.invalid>
> 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
James B. (Guest)
on 2009-04-27 04:46
Sam G. 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?
Sam G. (Guest)
on 2009-04-27 06:17
Solved the problem. I was using attr_accessible and forgot to include
the date_select field in it. Stupid of me.


James B. wrote:
> Sam G. 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?
Sam G. (Guest)
on 2009-04-27 06:17
Solved the problem. I was using attr_accessible and forgot to include
the date_select field in it. Stupid of me.

thanks

Frederick C. wrote:
> On Apr 26, 8:20�pm, Sam G. <removed_email_address@domain.invalid>
> 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.