problem to display date format with rails 3.0 ajax using js.erb file
Hi
In my application I append a date received from the user in a dd/mm/yyyy format for example("11/11/2010") to a selection list using ajax and js.erb filemy selection list code is
<select name="hour[reported_date]" id="customDate_link_hours">
<option value="Today">Today</option>
<option value="Yesterday">Yesterday</option>
<option value="Custom_range">Select Date</option>
</select>
in the controller I assign the date which is received from the user to a @display_date variable
@display_date=params[:hour][:reported_date]
in the js.erb file i do
$('#customDate_link_hours').append($('<option></option>').attr('value',<%=@display_date%>).attr('selected',true).text(<%=@display_date%>))
the function is working ok but i getting very strange final input
for example, if i add the date "18/11/2010" th开发者_Python百科e received appended value to the select list is "0.013888888888" if i get the date "2/11/201" the received appended value to the select list is "0.00009045687471733". I suspect that the problem is in the "/" character of the date format because when i tried to enter some other strings like "18112010" every thing was working ok I will mostly appreciate if someone could tell me what to do in order to solve thisYou need quotes around your ERB block:
$('#customDate_link_hours')
.append($('<option></option>')
.attr('value','<%=@display_date%>')
.attr('selected',true).text('<%=@display_date%>'));
Right now Javascript is seeing a literal 2/11/201 and treating it as a division.
精彩评论