下午全部,
我觉得这段时间很令人困惑。也许是因为我现在对时间没有概念,但我的管理员中有以下内容:
t.boolean "mon", default: false
t.boolean "tue", default: false
t.boolean "wed", default: false
t.boolean "thu", default: false
t.boolean "fri", default: false
t.time "start"
t.time "end"
我的预订中有以下表格:
<%= simple_form_for(@booking) do |f| %>
<% if @booking.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@booking.errors.count, "error") %> prohibited this booking from being saved:</h2>
<ul>
<% @booking.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<ul>
<li><%= f.label :first_name %></li>
<li><%= f.text_field :first_name %></li>
<li><%= f.label :last_name %></li>
<li><%= f.text_field :last_name %></li>
<li><%= f.label :email %></li>
<li><%= f.text_field :email %></li>
<li><%= f.date_select :start_datetime %></li>
<li><%= f.time_select :start_datetime, :ignore_date => true, :minute_step => 15 %></li>
<li><%=f.input :length, input_html: { :style=> 'width: 120px'}, collection: [['30 Mins', 30], ['1 Hour', 60]], :class => 'dropdown-toggle' %></li>
</ul>
我希望能够在预订上输入与用户设置的时间和天数相匹配的信息。
有人能帮我理清时间问题吗。我试图用最务实的方式来做这件事,但失败了。
谢谢。
因此,您希望能够预订一个管理员可用的日子,而您希望禁用那些没有管理员的日子。一个简单的date_select
会给你带来麻烦。您应该使用JavaScript日期选择器,如jQuery日期选择器插件。他们有一个名为beforeShowDay的函数,可以让你选择一天是否可用:
http://api.jqueryui.com/datepicker/#option-展会前
$(function () {
function isAvailable(day) {
var cssClass = ""; // Becomes the default.
// currentAdmin will have to be written by you.
// You'll likely have to pull in information about
// the admin via some info in the page or, better,
// via JSON.
if (currentAdmin.isAvailableOn(day)) {
return [true, cssClass];
} else {
return [false, cssClass];
}
}
$("#dp").datepicker({
beforeShowDay: isAvailable
});
});