Hi, Could anybody please help me to search the record by date I have one products table. In that table I have created_at.I want to search the records by date. I mean, if i select month as january and year as 2006 then i want to get the list as per that month only. Ex: Created At Product Price 2006-09-18 Ruby 4.5 2006-09-18 Ruby 4.5 2006-08-18 Ruby 4.5 2006-08-04 shq 8.0 If i select September then I should be able to see Created At Product Price 2006-09-18 Ruby 4.5 2006-09-18 Ruby 4.5 This is the code i wrote::: in rhtml file <%= start_form_tag :action => ''month'' %> <%= date_select ''project'', ''created_at'',:order=>[:month]%> <%= submit_tag "Go" %> <%= end_form_tag %> In the controller:: def month userId=@session[''user''][''id''] @projects = Project.find_by_sql("select * from projects where user_id=''#{userId}'' and month(created_at)= ''#{[:created_at]}''") end If i give the month as 9 and user id, then i''m getting the result in the right way. but i want to do it dynamically. so wats the problem with the code?? Thanks and Regards, Harish -- 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 -~----------~----~----~----~------~----~------~--~---
On 9/20/06, Naga harish Kanegolla <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hi, > Could anybody please help me to search the record by date > > I have one products table. In that table I have created_at.I want to > search the records by date. > > I mean, if i select month as january and year as 2006 then i want to get > the list as per that month only. > Ex: > Created At Product Price > 2006-09-18 Ruby 4.5 > 2006-09-18 Ruby 4.5 > 2006-08-18 Ruby 4.5 > 2006-08-04 shq 8.0 > > If i select September then I should be able to see > > Created At Product Price > 2006-09-18 Ruby 4.5 > 2006-09-18 Ruby 4.5 > > This is the code i wrote::: > in rhtml file > <%= start_form_tag :action => ''month'' %> > <%= date_select ''project'', ''created_at'',:order=>[:month]%> > <%= submit_tag "Go" %> > <%= end_form_tag %> > > > In the controller:: > def month > userId=@session[''user''][''id''] > @projects = Project.find_by_sql("select * from projects where > user_id=''#{userId}'' and month(created_at)= ''#{[:created_at]}''") > end > > If i give the month as 9 and user id, then i''m getting the result in the > right way. but i want to do it dynamically. so wats the problem with the > code?? > > Thanks and Regards, > Harish >Have you tried params[:created_at] instead of just [:created_at]? Cheers Max --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Yes I tried that also. then it gave me Stack level too deep error. Max Muermann wrote:> On 9/20/06, Naga harish Kanegolla <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: >> Created At Product Price >> >> userId=@session[''user''][''id''] >> > Have you tried params[:created_at] instead of just [:created_at]? > > Cheers > Max-- 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 -~----------~----~----~----~------~----~------~--~---
Naga harish Kanegolla wrote:> Yes I tried that also. then it gave me Stack level too deep error. > > Max Muermann wrote: >> On 9/20/06, Naga harish Kanegolla <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> >> wrote: >>> Created At Product Price >>> >>> userId=@session[''user''][''id''] >>> >> Have you tried params[:created_at] instead of just [:created_at]? >> >> Cheers >> Maxhai naga just tried this Project.find_by_sql("select * from projects where user_id=''#{userId}'' and month(created_at)= ''#{params[:project][''created_at(2i)''].to_i}''") it may be working regards Narayana -- 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 -~----------~----~----~----~------~----~------~--~---
Narayana Karthick wrote: Hi Narayana Its giving the same problem. I''m not getting list of records. Its taking the variable as null. So I think the problem is with the rhtml file. I think i have to give the select statement correctly. could u please check this. <%= start_form_tag :action => ''month'' %> <%= date_select ''project'', ''created_at'',:order=>[:month]%> <%= submit_tag "Go" %> <%= end_form_tag %>> Project.find_by_sql("select * from projects where > user_id=''#{userId}'' and month(created_at)= > ''#{params[:project][''created_at(2i)''].to_i}''") > it may be working > > regards > Narayana-- 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 -~----------~----~----~----~------~----~------~--~---
Naga harish Kanegolla wrote:> Narayana Karthick wrote: > Hi Narayana > Its giving the same problem. I''m not getting list of records. Its > taking the variable as null. > So I think the problem is with the rhtml file. I think i have to give > the select statement correctly. could u please check this. > > <%= start_form_tag :action => ''month'' %> > <%= date_select ''project'', ''created_at'',:order=>[:month]%> > <%= submit_tag "Go" %> > <%= end_form_tag %> > >> Project.find_by_sql("select * from projects where >> user_id=''#{userId}'' and month(created_at)= >> ''#{params[:project][''created_at(2i)''].to_i}''") >> it may be working >> >> regards >> Narayanahai naga, just tried this in rhtml <%= date_select(:project,:created_at, :order=>[:month]) %> this having the month value returned in Integer ex: if u selected April below code give the value 4 params[:project][''created_at(2i)''].to_i regards Narayana -- 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 -~----------~----~----~----~------~----~------~--~---
Hi Narayan, Still its not coming. I have tried puts params[:project][''created_at(2i)''].to_i I have seen in the console. Its giving the value ''0''. So wat should be done??> just tried this in rhtml > > <%= date_select(:project,:created_at, :order=>[:month]) %> > > this having the month value returned in Integer ex: if u selected April > below code give the value 4 > params[:project][''created_at(2i)''].to_i > > regards > Narayana-- 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 -~----------~----~----~----~------~----~------~--~---
Naga harish Kanegolla wrote:> Hi Narayan, > Still its not coming. I have tried puts > params[:project][''created_at(2i)''].to_i > I have seen in the console. Its giving the value ''0''. So wat should be > done?? > > >> just tried this in rhtml >> >> <%= date_select(:project,:created_at, :order=>[:month]) %> >> >> this having the month value returned in Integer ex: if u selected April >> below code give the value 4 >> params[:project][''created_at(2i)''].to_i >> >> regards >> Narayanahai Naga, I am checking the thing, for me it return the month value correctly. U just try this def month render_text params[:project][''created_at(2i)''].to_i end & see whether it render the month value or not. & tell me what error was occured in detail regards, Narayana -- 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 -~----------~----~----~----~------~----~------~--~---
Hi narayana, It renedered me the correct value only. but wen trying @projects= Project.find_by_sql("select * from projects where user_id=''#{userId}'' and month(created_at)= ''#{params[:project][''created_at(2i)''].to_i}''") I''m getting not getting the list of records. So wat should i do?? Regards, Harish> I am checking the thing, for me it return the month value correctly. > U just try this > def month > render_text params[:project][''created_at(2i)''].to_i > end > & see whether it render the month value or not. > & tell me what error was occured in detail > > regards, > Narayana-- 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 -~----------~----~----~----~------~----~------~--~---
Naga harish Kanegolla wrote:> Hi narayana, > It renedered me the correct value only. but wen trying @projects= > Project.find_by_sql("select * from projects where user_id=''#{userId}'' > and month(created_at)= ''#{params[:project][''created_at(2i)''].to_i}''") > I''m getting not getting the list of records. So wat should i do?? > > Regards, > Harish > >> I am checking the thing, for me it return the month value correctly. >> U just try this >> def month >> render_text params[:project][''created_at(2i)''].to_i >> end >> & see whether it render the month value or not. >> & tell me what error was occured in detail >> >> regards, >> Narayanahi Harish, u just tried the below thing in ur db just test the query & look whether is working or not for ex:(hard code the value) select * from projects where user_id= 23 and month(created_at)= 9 regards, Narayana -- 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 -~----------~----~----~----~------~----~------~--~---
This is a totally different approach than the one you are taking (and kind of ugly), but you could try... Project.find(:all, :conditions => {"created_at like ", "''" + params[:year] + "-" + params[:month] + "%''"}) This seems to work in the console. Not sure it''s production code, but maybe it will help give ideas. Good Luck, Nathan On Wed, 2006-09-20 at 07:43 +0200, Naga harish Kanegolla wrote:> Hi, > Could anybody please help me to search the record by date > > I have one products table. In that table I have created_at.I want to > search the records by date. > > I mean, if i select month as january and year as 2006 then i want to get > the list as per that month only. > Ex: > Created At Product Price > 2006-09-18 Ruby 4.5 > 2006-09-18 Ruby 4.5 > 2006-08-18 Ruby 4.5 > 2006-08-04 shq 8.0 > > If i select September then I should be able to see > > Created At Product Price > 2006-09-18 Ruby 4.5 > 2006-09-18 Ruby 4.5 > > This is the code i wrote::: > in rhtml file > <%= start_form_tag :action => ''month'' %> > <%= date_select ''project'', ''created_at'',:order=>[:month]%> > <%= submit_tag "Go" %> > <%= end_form_tag %> > > > In the controller:: > def month > userId=@session[''user''][''id''] > @projects = Project.find_by_sql("select * from projects where > user_id=''#{userId}'' and month(created_at)= ''#{[:created_at]}''") > end > > If i give the month as 9 and user id, then i''m getting the result in the > right way. but i want to do it dynamically. so wats the problem with the > code?? > > Thanks and Regards, > Harish >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi Narayan, It worked me wen i hardcoded also. But thats not working only wen i use params[:project]['':created_at(2i)''].to_i So any other idea?? Regards, Harish> hi Harish, > > u just tried the below thing in ur db just test the query & look > whether is working or not > for ex:(hard code the value) > select * from projects where user_id= 23 > and month(created_at)= 9 > > regards, > Narayana-- 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 -~----------~----~----~----~------~----~------~--~---
Naga harish Kanegolla wrote:> Hi Narayan, > It worked me wen i hardcoded also. But thats not working only wen i > use params[:project]['':created_at(2i)''].to_i > So any other idea?? > > Regards, > Harish > > >> hi Harish, >> >> u just tried the below thing in ur db just test the query & look >> whether is working or not >> for ex:(hard code the value) >> select * from projects where user_id= 23 >> and month(created_at)= 9 >> >> regards, >> NarayanaHi Harish If am not wrong The problem might be some where else bcoz it render the correct value for params[:project]['':created_at(2i)''].to_i. u just do one thing just copy the error page & paste here, I will try to fix it. Regards Narayana -- 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 -~----------~----~----~----~------~----~------~--~---
Hi Narayana, Its rendering the correct value and also it gave the list wen i hard coded. But by dynamically its not coming. Its not giving any error. But I''m getting the nil records(Empty records). If I try september month I should get the records of september but it gave like this.. Created At Project Price Thats it.. Thanks and Regards, Harish> Hi Harish > If am not wrong The problem might be some where else bcoz it render the > correct value for params[:project]['':created_at(2i)''].to_i. u just do > one thing just copy the error page & paste here, I will try to fix it. > > Regards > Narayana-- 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 -~----------~----~----~----~------~----~------~--~---
Naga harish Kanegolla wrote:> Hi Narayana, > Its rendering the correct value and also it gave the list wen i hard > coded. But by dynamically its not coming. Its not giving any error. But > I''m getting the nil records(Empty records). > If I try september month I should get the records of september but it > gave like this.. > > Created At Project Price > > Thats it.. > > Thanks and Regards, > Harish > > >> Hi Harish >> If am not wrong The problem might be some where else bcoz it render the >> correct value for params[:project]['':created_at(2i)''].to_i. u just do >> one thing just copy the error page & paste here, I will try to fix it. >> >> Regards >> NarayanaHi Harish, shall we chat in the gmail about the problem my id: karthick.glinfo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org Regards Narayana -- 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 -~----------~----~----~----~------~----~------~--~---
Hi Narayana, Its ok. I added u in Google talk.. Harish> > Hi Harish, > shall we chat in the gmail about the problem > my id: karthick.glinfo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > > Regards > Narayana-- 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 -~----------~----~----~----~------~----~------~--~---
Hi Narayana, Its working good now. I just took colon in the code. Thanku very much for ur help.. Bye Bye, Regards, harish -- 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 -~----------~----~----~----~------~----~------~--~---