Hi, first and foremost sorry for my english. I have a pbroblem trying to built a search by data. My view is a simple text_field: <% form_tag ({:action =>''buscadata''},{:class => ''lgn''}) do%> <!-- cuando pulse el boton ira a buscadata de lgn --> <%= stylesheet_link_tag "show" %> <h1>Busqueda por fechas de LGN</h1> <p> <b><%=''Introduzca Fecha inicial (DD/MM/AA)''%></b><br /> <!--para introducir dia mes y año del inicio de la busqueda--> <%= text_field_tag :dia, params[:dia_ini]%> <%= text_field_tag :mes, params[:mes_ini]%> <%= text_field_tag :any, params[:any_ini]%> </p> <p> <b><%=''Introduzca Fecha Final (DD/MM/AA)''%></b><br /> <!--para introducir dia mes y año del inicio de la busqueda--> <%= text_field_tag :dia, params[:dia_fin]%> <%= text_field_tag :mes, params[:mes_fin]%> <%= text_field_tag :any, params[:any_fin]%> </p> <%= submit_tag "Buscar entre las fechas seleccionadas", :name=>nil%> <%end%> ------------------------------------------- In the controller I search @lgns created between the two dates: def buscadata date1 =parse_date("#{params[:any_ini]}/#{params[:mes_ini]}/#{params[:dia_ini]}") date2 =parse_date("#{params[:any_fin]}/#{params[:mes_fin]}/#{params[:dia_fin]}") if date1 and date2 @lgns=Lgn.find(:all, :conditions => [''created_at >=? and created_at <=?'', date1, date2 ]) end end ###################################################################################################### private def parse_date(str, format=''%Y/%m/%d'') begin date = Date.parse(str, format) #strptime return date rescue ArgumentError return false end end ---------------------------- Finally I show @lgns find, buscadata view it''s the same that index view. But I have a problem, @lgns it''s a nil object. Somebody can help me?? I cant see whats wrong :( -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Sorry, the search is by date no by data -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Now it shows me the view but with all the objects :( My new code: CONTROLLER: def buscadata date1 =parse_date("#{params[:dia_ini]}/#{params[:mes_ini]}/#{params[:any_ini]}") date2 =parse_date("#{params[:dia_fin]}/#{params[:mes_fin]}/#{params[:any_fin]}") if date1 and date2 @lgns=Lgn.find(:all, :conditions => [''created_at >=? and created_at <=?'', date1, date2 ]) end end ###################################################################################################### private def parse_date(str, format=''%Y/%m/%d'') begin date =str.to_date #Date.parse(str, format) #strptime return date rescue ArgumentError return false end end the view when I introduce the date: <% form_tag ({:action =>''buscadata''},{:class => ''lgn''}) do%> <!-- cuando pulse el boton ira a buscadata de lgn --> <%= stylesheet_link_tag "show" %> <h1>Busqueda por fechas de LGN</h1> <p> <b><%=''Introduzca Fecha inicial (DD/MM/AA)''%></b><br /> <!--para introducir dia mes y año del inicio de la busqueda--> <%= text_field_tag :dia_ini, params[:dia_ini]%> <%= text_field_tag :mes_ini, params[:mes_ini]%> <%= text_field_tag :any_ini, params[:any_ini]%> </p> <p> <b><%=''Introduzca Fecha Final (DD/MM/AA)''%></b><br /> <!--para introducir dia mes y año del inicio de la busqueda--> <%= text_field_tag :dia_fin, params[:dia_fin]%> <%= text_field_tag :mes_fin, params[:mes_fin]%> <%= text_field_tag :any_fin, params[:any_fin]%> </p> <%= submit_tag "Buscar entre las fechas seleccionadas", :name=>nil%> <%end%> the view when I show the results it''s like the index view -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 5 Dec 2008, at 16:58, Jose vicente Ribera pellicer wrote:> > Now it shows me the view but with all the objects :( >Have you checked whether your parse_date function is creating the correct dates? Fred> My new code: > > CONTROLLER: > def buscadata > date1 > =parse_date("#{params[:dia_ini]}/#{params[:mes_ini]}/ > #{params[:any_ini]}") > date2 > =parse_date("#{params[:dia_fin]}/#{params[:mes_fin]}/ > #{params[:any_fin]}") > if date1 and date2 > @lgns=Lgn.find(:all, :conditions => [''created_at >=? and > created_at <=?'', date1, date2 ]) > end > end > ###################################################################################################### > private > > def parse_date(str, format=''%Y/%m/%d'') > begin > date =str.to_date #Date.parse(str, format) > #strptime > return date > rescue ArgumentError > return false > end > end > > > the view when I introduce the date: > <% form_tag ({:action =>''buscadata''},{:class => ''lgn''}) do%> <!-- > cuando pulse el boton ira a buscadata de lgn --> > <%= stylesheet_link_tag "show" %> > > > <h1>Busqueda por fechas de LGN</h1> > > <p> > <b><%=''Introduzca Fecha inicial (DD/MM/AA)''%></b><br /> <!--para > introducir dia mes y año del inicio de la busqueda--> > <%= text_field_tag :dia_ini, params[:dia_ini]%> > <%= text_field_tag :mes_ini, params[:mes_ini]%> > <%= text_field_tag :any_ini, params[:any_ini]%> > </p> > <p> > <b><%=''Introduzca Fecha Final (DD/MM/AA)''%></b><br /> <!--para > introducir dia mes y año del inicio de la busqueda--> > <%= text_field_tag :dia_fin, params[:dia_fin]%> > <%= text_field_tag :mes_fin, params[:mes_fin]%> > <%= text_field_tag :any_fin, params[:any_fin]%> > </p> > > <%= submit_tag "Buscar entre las fechas seleccionadas", :name=>nil%> > > <%end%> > > > the view when I show the results it''s like the index view > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Solved....(mounth/day/year).to_date it''s the correct form. Thanks a lot -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---