我正在做这样的请求:
http://localhost:3000/api/v1/events?interval=1d
OR
http://localhost:3000/api/v1/events?due={timestamp}
我的EventsController
def index
if params[:interval]
@events = current_user.events.where(:time => Time.now..Time.now + params[:interval].to_i.day)
elsif params[:due]
#I need some code here
else
@events = current_user.events
end
render json: @events
end
如何配置控制器使GET“/ events?due = {timestamp}”工作?
答案 0 :(得分:0)
@events = current_user.events.where("time < ?", params[:due])
答案 1 :(得分:0)
如果截止日期是准确的时间,那么您可以这样做:
@events = current_user.events.where(time: params[:due])