2013-11-27 33 views
0

下午所有,根據管理數據爲用戶檢查時間表

我發現這次很混亂。也許是因爲我沒有時間觀念,但現在我已經在我的管理的情況如下:

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> 

我希望能夠爲在預訂上輸入以匹配在用戶中設置的時間和日期。

任何人都可以幫助我圍繞這個時間問題。我試圖以最務實的方式做到這一點,但失敗了。

謝謝。

回答

1

所以,你希望能夠預定一個管理員可用的日子,並且你想禁用那些他們不在的日子。您將遇到簡單的date_select問題。你應該使用JavaScript日期選擇器,比如jQuery datepicker插件。他們有一個叫beforeShowDay功能,它可以讓你選擇,如果每天是否可用:

http://api.jqueryui.com/datepicker/#option-beforeShowDay

$(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 
    }); 
    }); 
+0

我從來沒有真正使用jQuery的。你能否給我一些想法,我將如何使用管理表中的代碼來允許顯示的日期和時間。 –

+0

以下是關於如何將此功能與您的應用程序集成的更長時間的寫作。 http://stackoverflow.com/questions/12178385/rails-how-to-add-tooltip-events-in-datepicker-and-limit-them-in-few-months這就是說,如果你沒有很多jQuery或Rails的經驗,對於初學者項目來說這可能有點多。 –

+1

挑戰接受 –