Reputation: 181
I'm trying to figure out how to get and insert the date in my database using the select button in my view : <%= select_date Date.today, :date %>
and in the migration I have a :date
coloumn.
thanks.
Upvotes: 1
Views: 329
Reputation: 4295
With the way that you have it you would have to set this explicitly
Date.civil(params[:date][:year].to_i, params[:date][:month].to_i, params[:date][:day].to_i)
to get the date.
However, an easier way to do this would be to change the select.
<%= select_date :model, :date %>
or
<%= f.select_date :date %>
depending on how you are expressing the form.
Then just add a before_create
method to the model to set the current date:
before_create :start_with_todays_date
def start_with_todays_date
self.date = Date.today
end
Upvotes: 1
Reputation: 4930
I would suggest you to read the section 2. Dealing with Model Objects of the form helpers guide or at least the ruby on rails starting guide to figure out how to build a simple model and write controller and view (include new/edit views which contains form) for it.
Upvotes: 0