Skip to content

Instantly share code, notes, and snippets.

@bernardobarreto
Created November 20, 2017 10:32
Show Gist options
  • Save bernardobarreto/b021285269b2b09a69d30efe39b72c94 to your computer and use it in GitHub Desktop.
Save bernardobarreto/b021285269b2b09a69d30efe39b72c94 to your computer and use it in GitHub Desktop.
rails controller concern example
module IncrementableVisits
extend ActiveSupport::Concern
included do
before_action :increment_visits, only: [:index, :show, :new, :edit]
end
def increment_visits
current_user.inc(visits: 1) # Mongoid ODM example
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment