Here is the table:
|policies|
|id| |name| |date|
1 ABC 2013-01-01
2 DEF 2013-01-21
Here is the controller:
class PolicyController < ApplicationController
def index
@policies = Policy.find(:all,:conditions=>['date BETWEEN ? AND ?',params[cam],params[:cam2] ])
end
end
Here is the model:
class Policy < ActiveRecord::Base
end
Here is the view:
<% CalendarDateSelect.format=(:hyphen_ampm )%>
<% calendar_date_select_style "silver" %>
<% translation_calendar %>
<% form_tag :controller=>"policy",:action=>"index" do %>
From: <%= calendar_date_select_tag "cam", params[:cam] %>
To: <%= calendar_date_select_tag "cam2",params[:cam2] %>
<%= submit_tag "Search", :name => nil %></p>
<% end %>
<% @policies.each |p| do %>
<%= p.date %>
<% end %>
How can block the SEARCH button until my 2 calendar text have values?
I tried this:
class Policy < ActiveRecord::Base
validates_presence_of :cam
end
Please somebody can help me please or maybe a javascript?
I will appreciate all kind of help.
Here is what friends told me:
named_scope :by_calendar_date,lambda { |cam1, cam2| } {
if cam1.nil? && cam2.nil?
scoped
elsif cam1.nil?
where("date < ?",cam2)
elsif cam2.nil?
where("date > ?", cam1)
else
where("date BETWEEN ? AND ?",cam1,cam2)
end
}
#this would perform the same functionality so both are not needed but just for edification
def self.by_calendar_date(cam1,cam2)
if cam1.nil? && cam2.nil?
scoped
elsif cam1.nil?
where("date < ?",cam2)
elsif cam2.nil?
where("date > ?", cam1)
else
where("date BETWEEN ? AND ?",cam1,cam2)
end
end