Created
June 18, 2011 16:09
-
-
Save kmcd/1033232 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= form_tag(availability_path, :method => :delete) do |form|%> | |
Start: <%= select_date(@start_date, :prefix => :start_date) %> <br/> | |
End: <%= select_date(@end_date, :prefix => :end_date) %> <br/> | |
<%= submit_tag("Check availability") %> | |
<% end %> | |
<table class='availability'> | |
<tr> | |
<th>Date</th> | |
<% @rooms.each do |room| %> | |
<th><%= room.number %></th> | |
<% end %> | |
</tr> | |
<% (@start_date..@end_date).to_a.each do |date| %> | |
<tr> | |
<td><%= date.to_s(:short) %></td> | |
<% @rooms.each do |room| %> | |
<td class="<%= availablity_css room, date %>"> | |
| |
</td> | |
<% end %> | |
</tr> | |
<% end %> | |
</table> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def search | |
@rooms = Room.all | |
@start_date = parse_date(params[:start_date]) || Date.today | |
@end_date = parse_date(params[:end_date]) || 30.days.from_now.to_date | |
end | |
def parse_date(date) | |
return unless date | |
Date.civil date[:year].to_i, date[:month].to_i, date[:day].to_i | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def availablity_css(room,date) | |
if room.available? date | |
'free' | |
else | |
'taken' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment