Skip to content

Instantly share code, notes, and snippets.

@adriangohjw
Created August 7, 2021 08:02
Show Gist options
  • Save adriangohjw/a081d63ebc10df611dfa37ab423e8a97 to your computer and use it in GitHub Desktop.
Save adriangohjw/a081d63ebc10df611dfa37ab423e8a97 to your computer and use it in GitHub Desktop.
refactoring with query object
class PopularSalariesQuery
def all
# return data in whatever shape is needed
end
end
# Somewhere in the controller
@data = PopularSalariesQuery.new.all
class SalaryGroup < ApplicationRecord
# some simple code
end
class SalaryGroup < ApplicationRecord
# some simple code
def self.popular_salaries
# return data in whatever shape is needed
end
end
# Somewhere in the controller
@data = SalaryGroup.popular_salaries
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment