Railsで簡易カレンダ
今、体重管理のためのWebアプリをRailsの勉強をかねて、作ろうとしている。
カレンダにその日の体重を表示できるようにしたいのだが、
Rails カレンダでgoogle先生に質問したが、よく解らない回答
だったので、自分で作ってみた。
無保証です。使用により不都合が起きても責任を取りません。
コントローラ側
def list_cal
if params[:date]
begin
indicate = params[:date].split("-")
session[:date] = Date.new(indicate[0].to_i,indicate[1].to_i,indicate[2].to_i)
rescue
flash[:notice] = "Invalid #{params[:date]}"
end
end
unless session[:date]
session[:date] = Date.today
end
@date = session[:date]
end
end
list_cal.html.erb
<%= link_to('先月',:action=>'list_cal',:date=> @date.last_month) -%>
<span><%= @date.year %>年 <%= @date.month%>月</span>
<%= link_to('来月',:action=>'list_cal',:date=>@date.next_month) -%>
<table>
<thead>
<tr>
<th>日</th>
<th>月</th>
<th>火</th>
<th>水</th>
<th>木</th>
<th>金</th>
<th>土</th>
</tr>
</thead>
<tbody>
<tr>
<% cnt = 0 -%>
<% @date.beginning_of_month.beginning_of_week.yesterday.upto
(@date.end_of_month.next_week(:monday).yesterday.yesterday) do |d| -%>
<% if cnt != 0 && cnt % 7 == 0 -%>
</tr>
<tr>
<% end -%>
<td> <%=d.day-%> </td>
<% cnt+=1 -%>
<% end -%>
</tr>
</tbody>
</table>
現時点ではCSSまったくつけていないが、これから土、日の色を変えたり等を
行う予定。
さらに祝日もhttp://www.h3.dion.ne.jp/~sakatsu/holiday_logic4.htm#Ruby を利用させていただいて、表示できるようにする。
日付はリンクにして、その日の体重等を書き込む入力画面に遷移する予定。
今週の土曜日が解らなかったので、来週の月曜日の昨日、昨日にしているのが、 かなりダサい。
イメージ 2008年4月
日 | 月 | 火 | 水 | 木 | 金 | 土 |
---|---|---|---|---|---|---|
30 | 31 | 1 | 2 | 3 | 4 | 5 |
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 1 | 2 | 3 |
| 固定リンク
|
「rails」カテゴリの記事
- Railsで掲示板を作成(2009.08.07)
- undefined method use_transactional_fixtures=(2009.05.14)
- LIBMYSQL.dll が見つかりません(2009.04.25)
- Railsで簡易カレンダ(2008.02.07)
- windowsでselenium on railsがinvalid args ./C:/applicationのエラー(2009.04.29)
コメント