2007年12月5日 星期三

取得 select_date 所設定的值, 範圍 prefix

View
<% form_for :task ,:url => {:action => 'query_date_tasks' } do |form|%>
 
 <%= select_date Date.today, :prefix => "stay_from", :include_blank => true %>


<%= select_date Date.today, :prefix => "stay_to", :include_blank => true %>
<%= submit_tag "submit" %>
<% end %>

:prefix 用來設定參數的名稱
:params => { :stay_from => { :year => 2007, :month => 12, :day => 5}}


Controller

def query_date_tasks
 date_stay_from = Date.new(params[:stay_from][:year].to_i,
               params[:stay_from][:month].to_i,
               params[:stay_from][:day].to_i)

 date_stay_to = Date.new(params[:stay_to][:year].to_i,
             params[:stay_to][:month].to_i,
             params[:stay_to][:day].to_i)

 @tasks = Task.find(:all, :conditions => ["finish_time BETWEEN ? AND ?", date_stay_from, date_stay_to])

 render :action => 'list_all_tasks'
end

沒有留言: