controller:
class LogsController < ApplicationController
helper :calendar
before_filter(
RequestPreprocessor.apply_to(''log.accesstime'') { |d|
d && Date.strptime(d, ''%Y-%m-%d %l:%M:%S'') }, :only
=> [ :search, :index ])
before_filter :login_required
def index
query
render_action ''query''
end
def search
@logs = Log.find_by_sql [''SELECT url FROM logs WHERE user LIKE ? AND
accesstime > ? and accesstime < ?'',
"%#{@params[''T1'']}%",
"#{@params[''log''][''T2'']}",
"#{@params[''log''][''T3'']}"]
end
view
<h3>Query User</h3>
<form method="post" action="/logs/search">
Search User:
<input type="text" name="T1" size="20">
Between Begin Date:
<%= calendar_field ''log'', ''T2'',
{ :class => ''date'', :field_title =>
''T2'', :button_title => ''Show calendar''
},
{ :ifFormat => ''%Y-%m-%d %l:%M:%S'', :firstDay => 1,
:step => 1, :showOthers => true, :cache => true } %>
Between End Date:
<%= calendar_field ''log'', ''T3'',
{ :class => ''date'', :field_title =>
''T3'', :button_title => ''Show calendar''
},
{ :ifFormat => ''%Y-%m-%d %l:%M:%S'', :firstDay => 1,
:step => 1, :showOthers => true, :cache => true } %>
<input name="B2" input type="submit"
value="Query">
</form>
You will need the calendar helper (
http://wiki.rubyonrails.com/rails/pages/CalendarHelper ).
On 9/28/05, Nick Brutyn
<brutyn_nick-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org>
wrote:>
> hey i need 2 select list with dates (day, month, year) for a search
> engine,
> and then i must find those records between those date.
>
> Does anyone has any example code for the controller and the rhtml??
>
> thanks in advance
>
>
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
--
"Force Feedback Computing Since 1984"
http://www.modelm.org
http://www.clubpacswestmi.net/sweeney/
http://www.clubpacswestmi.net
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails