My ‘Events’ table has 2 datetime values to store start and finish dates.
They used to be like this
.field
= f.label t :event_start_date
%br
= f.datetime_select :start_date
.field
= f.label t :event_finish_date
%br
= f.datetime_select :finish_date
I used the datetime picker addon and it works fine visually. However, since the fields changed from datetime_select to text_field, the values are not stored when a new event is created.
This is how it looks right now:
.field
= f.label t :event_start_date
%br
= f.text_field :start_date, :class=>"datetime_box", :size=>"17"
.field
= f.label t :event_finish_date
%br
= f.text_field :finish_date, :class=>"datetime_box", :size=>"17"
And this is the js in case anyone needs it:
$(function() {
$('.datetime_box').datetimepicker({
minDate: new Date(),
showOn: "button",
buttonImage: "../images/pais_vasco_conciertos_teatro_musica_grupos.png",
buttonImageOnly: true
});
});
Any idea how to overcome this problem and store the values?
Events controller
def create
categories = params[:category_ids] or []
@event = Event.new(params[:event].merge(:user_id => current_user.id, :category_ids => categories))
respond_to do |format|
if @event.save
#Mailer to seek appoval
format.html { redirect_to @event, notice: 'Event was successfully created.' }
format.json { render json: @event, status: :created, location: @event }
else
format.html { render action: "new" }
format.json { render json: @event.errors, status: :unprocessable_entity }
end
end
end
This site works in 4 languages. This error only shows up under English language. So, I guess it has to do with the format..
Examples of format:
Spanish and French (works)
"start_date"=>"30/01/2013 16:39",
"finish_date"=>"31/01/2013 16:39",
Basque(works)
"start_date"=>"2013/01/30 16:38",
"finish_date"=>"2013/01/31 16:38",
English(does NOT work)
How can I make that MM/DD/YY work? Thanks again
"start_date"=>"01/30/2013 16:40",
"finish_date"=>"01/31/2013 16:40",
You need to make sure that the date, as a string, that is passed to the controller can be parsed by ruby. One way to do this is to pass a date and time format to datetimepicker. Experiment what format suits your needs and what can be parsed by ruby.
Try adding these options and see if that fixes your issue