Skip to content

Instantly share code, notes, and snippets.

@hron84
Forked from anonymous/application.js
Created November 12, 2012 22:25
Show Gist options
  • Save hron84/4062410 to your computer and use it in GitHub Desktop.
Save hron84/4062410 to your computer and use it in GitHub Desktop.
$('#nextmonth').on('click', fuction(e)) {
$.get('/rota_days/show.json?mon=12').success(function(data) {
rota_days = data
for ( i = 0; i < rota_days.length; i++)
{
rota_day = rota_days[0];
/* doing stuffs with rota_day */
}
});
)};
<table class = "rota">
<thead>
<th>Date</th>
<% @hospitals.each do |hosp| %>
<th><%= hosp.name%></th>
<% end %>
</thead>
<tbody>
<% @dates.each do |date| %>
<tr>
<td><%= date.to_s(:short) %></td>
<% (1..@hospitals.count).each do %>
<td></td>
<% end %>
</tr>
<% end %>
</tbody>
</table>
<%= link_to 'Next Month', rota_days_path(:month => 12), :id => 'nextmonth' %>
class RotaDaysController < ApplicationController
# GET /rota_days
# GET /rota_days.json
# load_and_authorize_resource
respond_to :json, :html
def index
@rota_days = RotaDay.all
# @dates = @rota_days.collect(&:day)
@hospitals = Hospital.all
t1 = Date.today.at_beginning_of_month
t2 = Date.today.end_of_month
@dates = (t1..t2).to_a
@title = "Rota"
respond_to do |format|
format.html # index.html.erb
format.json { render json: @rota_days }
end
end
def nextmonth
dfrom = Date.parse("#{Date.today.year}-#{sprintf("%02d", params[:mon].to_i)}-01")
dto = Date.parse("#{Date.today.year}-#{sprintf("%02d", params[:mon].to_i + 1)}-01")
@rota_days = RotaDay.where('rota_days.day BETWEEN ? AND ?', dfrom, dto)
respond_with(@rota_days)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment