Answer the question
In order to leave comments, you need to log in
How to display articles for a specific month in ruby on rails?
Actually. There are articles, you need to make a "where" filter so that articles for a certain month of all years are displayed. I thought to make the minimum and maximum dates, for example, for February it is 02/01/2015 and 02/31/2015 and display everything that is included in this section. But in a year, you will have to add another year to the filter, and this is no longer interesting. How to make this filter in general, tell me, please?
Answer the question
In order to leave comments, you need to log in
Show how you already wrote the filter code. In general, the year can be passed as a parameter.
Something like this:
@items = Item.where(
updated_at: Time.parse(params[:date])
.beginning_of_month..Time.parse(params[:date]).end_of_month
Model.where("MONTH(created_at) = ?", month)
See www.tutorialspoint.com/sql/sql-date-functions.htm#...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question