:::----------------------------------------------------------------------------------:::
Problem
--------->>>
I need to do search function based on date range selected by user.. In my databaase,for my date column i have this format '01-February-2010' but for my calendar format i have this format '01-02-2010'. So i can't get the whole result if i don't convert my date selected from calendar into my date format in my database. Basically, i need to convert this format "01-02-2010" into this format "01-February-2010".
My senior recommended me to use Date::MONTHNAMES to convert them.Thanks to him for helping me out.. Senpai,thanks a lot..(^_-)
:::----------------------------------------------------------------------------------:::
Coding3.....
----------->> controller
def date
from = params[:from_date].split("-")
start_date = from[0] + '-' + Date::MONTHNAMES[from[1].to_i] + '-'+ from[2]
to = params[:end_date].split("-")
to_date = to[0] + '-' + Date::MONTHNAMES[to[1].to_i] + '-' + to[2]
@date_search = Hacked.date_search(start_date,to_date)
end
>>>>>>> line 1 & 3 = get parameter value from view/search.rhtml and then split them into 3 part using .split and have this symbol("-") in between.
line 2 & 4 = combine them together again but for the [1], have them in full monthname using Date::MONTHNAMES eg. 'February' & convert them to integer.
line 5 =
----------> view/search.rhtml
<% form tag({:controller => :urcontrollername, :action => uractionname }, :method => 'get' ) do %>
Start Date
<% calendar_select_tag :from_date %>
End Date
<% calendar_select_tag :to_date %>
<% search_tag "Search!"
>>>>>> this form will accept 2 parameters value from users using calendar_select_tag and then refer to controller..
----------> view/result.rhtml
put ur own coding here, to view ur result...:)
>>>>>> results of the search should be displaying here
----------> urmodelname.rb
def self.date_search(start_date,to_date)
@date_search = Hacked.find(:all, :conditions => ["date between ? and ?",start_date,to_date]
end
>>>>>>> this will process ur request by finding all related data within the conditions
Tuesday, March 30, 2010
Thursday, March 4, 2010
OFC2 For Ruby on Rails
Bar code and use explicit statement from database.
def bar_code
@bar = Tablename.find_by_sql("Select name,total from tablename limit 0,5")
array_name =[] ###### declare new array to put value from name
amount = [] ###### declare new array to put value from total
@bar.each do |c|
array_name << c.name #### append value from name to array called array_name
amount << c.total #### append value from total to array named amount
end
title = Title.new("Top 5 Name")
bar = BarGlass.new
bar.values = [BarValue.new(amount[0]), BarValue.new(amount[1]), BarValue.new(amount[2]),BarValue.new(amount[3]),BarValue.new(amount[4])]
chart = OpenFlashChart.new
chart.set_title(title)
chart.add_element(bar)
x = XAxis.new
x.set_range (0,20,2)
chart.set_x_axis(x)
y = YAxis.new
y.set_labels(array)
chart.set_y_axis(y)
render :text => chart.to_s
end
---
Should be working ..:P
def bar_code
@bar = Tablename.find_by_sql("Select name,total from tablename limit 0,5")
array_name =[] ###### declare new array to put value from name
amount = [] ###### declare new array to put value from total
@bar.each do |c|
array_name << c.name #### append value from name to array called array_name
amount << c.total #### append value from total to array named amount
end
title = Title.new("Top 5 Name")
bar = BarGlass.new
bar.values = [BarValue.new(amount[0]), BarValue.new(amount[1]), BarValue.new(amount[2]),BarValue.new(amount[3]),BarValue.new(amount[4])]
chart = OpenFlashChart.new
chart.set_title(title)
chart.add_element(bar)
x = XAxis.new
x.set_range (0,20,2)
chart.set_x_axis(x)
y = YAxis.new
y.set_labels(array)
chart.set_y_axis(y)
render :text => chart.to_s
end
---
Should be working ..:P
Subscribe to:
Comments (Atom)