views:

32

answers:

1

Hi there,

I'm trying to let the user select his birthday with:

<% form_for :user, :url => users_path do |f| %>
  <%= f.date_select :birthday, :start_year => 2010 , :end_year =>1920, :discard_day => true %>
<% end %>

The problem is that it doesn't get saved... birthday is a date field in the users table and to save it I call

@user = User.new(params[:user])
@user.save

what could be the problem?

Thanks Maechi

A: 

The problem is due to discard day option that you choose. See the html code of date_select tag.You will get clue from there.

gsoni
Hi Gsoni, it's the same problem aswell if I remove the :discard_day tag! The date devides itself to 3 different params and doesnt get written in the correct variable!
Markus
I mean to say that collect the values of different params that are formed by date_select tag. Then create a date from those collected params and then pass these formated date in to your model to save it.Ex:- month = [:user]["birthday(1i)"] year = [:user]["birthday(2i)"] make a date in format you want because here you will need a default day.So add a day whatever you want. bdate = "1/month/year" and convert it into datetime object then bdate canbe saved.
gsoni
Great! I tried to use params[:user][:birthday(1i)] but that didn't work... what worked was params[:user]["birthday(1i)"] Thanks a lot!
Markus