I have controller that has
@account_info = @account_info.account_dates(params[:start_date], params[:end_date]) unless
params[:start_date].nil? || params[:end_date].nil?
Model has
self.table_name = 'UserAccounts'
scope :account_dates, -> (start_date, end_date) { where(account_date: start_date.to_date...(end_date.to_date + 1)) }
I have json created to display the data about account
accounts: [
{
name: "John"
account_date: "2016-12-27"
},
{
name: "Mike"
account_date: "2017-01-03"
},
{
name: "Jason"
account_date: "2014-01-01"
}
]
start_date and end_date are optional parameters. right now if i dont pass them i get all the entries shown above which is one of the requirement. second requirement is if i just pass start_date e.g 2016-12-27 then i get the entries between start_date and todays date so i'll get 2016-12-27 and "2017-01-03" entries from json. I am new to rails. can someone help me how can i update my code for second requirement?
Thanks
Aucun commentaire:
Enregistrer un commentaire