在提交带有错误消息的表单时,它将在错误加载新页面后呈现new.html.erb(呈现操作:“新”),脚本中的multidatepicker字段无法同时加载,路由显示为索引页面。
在新页面中,
日期选择器class = "pick hasDatepicker".
路由localhost:3000/leaves/new
(新页面)
在带有错误消息的创建操作中呈现新页面后,
datepicker class = "pick"
。路线localhost:3000/leaves
(索引页)
我该怎么办?...
leavescontroller.rb
def create # Create a new record in the Leave table
@leave = current_user.leaves.create leave_params
# @leave.user_id = session[:user_id]
@leave_dates = params[:datePick].split(',')
@leave.start_date = @leave_dates.first
@leave.end_date = @leave_dates.last
respond_to do |format|
if @leave.save
..//conditions
else
format.html { render action: "new" }
format.json { render json: @leave.errors, status: :unprocessable_entity }
end
end
new.html.rb
<%= render :partial => 'layouts/datepicker'%>
<script>
$(function() {
$('#datePick').multiDatesPicker({
beforeShowDay: function(date) {
var day = date.getDay();
return [day != 0 && day != 6];
}, // For disabling all "Sundays"
dateFormat : "d/m/yy",
maxDate : "+3m",
minDate : "0m",
multidate : true,
addDisabledDates : <%= raw @holidays %>
});
});
</script>
<body >
<div id="newentryrow">
<div id="newentrytext">
<label>Select Dates :</label>
</div>
<div id="newentryfield" >
<%= text_field_tag 'datePick', nil, placeholder: 'Select dates' ,class: 'pick', autoComplete: "off", :readonly => true %><br />
<label>Select multiple dates if you want to apply more than one day leave…</label>
</div>
</div>