How to do program in different way?

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

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.

On Friday, 18 July 2014 03:51:23 UTC-4, Ruby-Forum.com User wrote:

  find(:all, :conditions => ['month LIKE ?', "%#{search}%"])

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.

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 J.

Jaimin P. 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.

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

On Jul 18, 2014, at 6:54 AM, Jaimin P. [email protected] wrote:

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.

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.