Skip to content

Instantly share code, notes, and snippets.

@swrobel
Created April 11, 2020 23:42
Show Gist options
  • Save swrobel/871e35876b308a0ade689b1f8f113342 to your computer and use it in GitHub Desktop.
Save swrobel/871e35876b308a0ade689b1f8f113342 to your computer and use it in GitHub Desktop.
Generic finders for a rails base controller
def model
@model ||= controller_name.classify.constantize
end
def record
@record ||= records.find(params[:id])
end
def records
@records ||= policy_scope(model) # Requires Pundit
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment