rails 3, find_by_sql, date_format, too few arguments error
-
07-03-2021 - |
Question
I have the following find_by_sql and am getting a 'too few arguments' error. Any ideas to fix? Would like to just keep it as a find_by_sql
dates=find_by_sql(['select DATE(start_datetime) date_only, DATE_FORMAT(start_datetime,\'\%b \%D\') as formatted_date from events where area_id=1 group by date_only'])
thx
Solution
You need to use double percentage symbols to escape a percentage inside of a finder:
dates = find_by_sql(['select DATE(start_datetime) date_only, DATE_FORMAT(start_datetime,\'\%%b \%%D\') as formatted_date from events where area_id=1 group by date_only'])
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow