ruby on rails - Bind variables to ActiveRecord select -
in activerecord, how can bind prepared statement variables in select? example:
group.select('(extract(epoch created_at) / $1)::int interval') the $1 parameter calculated user input tempted concatenate strings, guess it's no ideal. in advance!
you can go around, must define method in model calculations need:
def self.interval_divided_by dividend group.select('(extract(epoch created_at))::int interval').interval / dividend end then use it:
group.interval_divided_by 4
Comments
Post a Comment