我尝试学习 RoR 并拥有以下代码。我只是认为它可以容易得多。我从 RoR 中了解到的是,你应该尽量不要重复,让事情尽可能简单。所以也许有人对此有一些建议:
if params[:select_date].present?
if params[:select_date] == '1'
params[:search][:date_started_at_gte] = Date.today.beginning_of_month
end
if params[:select_date] == '2'
params[:search][:date_started_at_gte] = Date.today - 1.months
end
if params[:select_date] == '3'
params[:search][:date_started_at_gte] = Date.today - 3.months
end
if params[:select_date] == '0'
params[:search][:date_started_at_gte] = params[:search][:date_started_at_gte]
params[:search][:date_started_at_lte] = params[:search][:date_started_at_lte]
end
else
params[:search][:date_started_at_gte] = Date.today.beginning_of_month
params[:search][:date_started_at_lte] = Date.today
end
谢谢!