Skip to content
tinto101 edited this page Sep 13, 2010 · 1 revision

Link to previous and next months

View

<%= calendar(:year => @date.year, :month =>@date.month, :first_day_of_week =>1, :next_month_text => link_to (">>", :action=>'index', :params => {:date => @date.next_month.strftime("%Y-%m")}), :previous_month_text => link_to ("<<",:action=>'index',:params => {:date => @date.last_month.strftime("%Y-%m")})) %>

Controller


def index @date = Time.parse("#{params[:date]} || Time.now") end

Explanation

the :year and :month are set by the new date attribute of the page and the previous_month_text and next_month_text month text have been set to be links that replace the value of the @date attribute to be the new month that the user would like to see.

Clone this wiki locally