Skip to content

Instantly share code, notes, and snippets.

@balvig
Created April 24, 2019 06:56
Show Gist options
  • Save balvig/8b6a9593468d6e6c992908d29ac0b0b4 to your computer and use it in GitHub Desktop.
Save balvig/8b6a9593468d6e6c992908d29ac0b0b4 to your computer and use it in GitHub Desktop.
@@ Model @@
-class Event
- def visitor
- User.last
- end
-
- def action
- "liked"
- end
-
- def recipe
- Recipe.last
- end
+class Event < ApplicationRecord
+ belongs_to :visitor, class_name: "User"
+ belongs_to :recipe
+ enum action: %i(liked)
def featured_visitor_recipe
visitor.recipes.last
@@ Controller @@
class EventsController < ApplicationController
def index
- @events = [Event.new]
+ @events = Event.all
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment