11155
(-- --)
July 18, 2014, 7:50am
1
I am using Ruby 1.9.3 and Rails 3.2.16.
I written program to get data for each month and I have add search
feature for month.
In Model:
def self.search(search)
if search
find(:all, :conditions => ['month LIKE ?', "%#{search}%"])
else
find(:all)
end
end
In controller:
def index
@quantities = Quantity.search(params[:search])
end
In view:
<%= form_tag quantities_path, :method => 'get' do %>
<p>
<%= text_field_tag :search, params[:search] %>
<%= submit_tag "Search", :name => nil %>
</p>
<% end %>
Now,Above program is only to get report for month.
I am trying to do program like if i enter day or month or year then
also i should get data corresponding day or month or year.
I tried several ways but i am not getting correct one.
Could anyone help in this?
Kind regards.
It’s hard to give much guidance without seeing the “several ways” or any details about your schema.
Why is “month” a string column? If you want to search by date range, it seems like a date column would be more useful.
For day + year reporting, how is that data stored?
–Matt Jones
11155
(-- --)
July 18, 2014, 12:54pm
3
It's hard to give much guidance without seeing the "several ways" or any
details about your schema.
Details of schema:
ActiveRecord::Schema.define(:version => 20140717071753) do
create_table "quantities", :force => true do |t|
t.string "title"
t.decimal "price", :precision => 8, :scale => 2
t.datetime "created_at", :null =>
false
t.datetime "updated_at", :null =>
false
t.string "day"
t.string "month"
t.string "year"
end
end
Why is "month" a string column? If you want to search by date range, it
seems like a date column would be more useful.
Yes, if i want to search by date then date column would be more useful.
What i am trying to do is If i want to get data for particular month or
day or year then How can i do it? I added search feature for searching.
Kind regards
11155
(-- --)
July 18, 2014, 1:07pm
4
Jaimin Pandya wrote in post #1152808:
Thank you for your reply.
I fixed just now. I can able to search to get data particularly for day
or month or year.
Kind regards.
You use date functions to find the dates of the first day of the month and the last day of the month, for instance, and search that range of dates.