Skip to content

Instantly share code, notes, and snippets.

@kaspth
Created April 26, 2025 21:19
Show Gist options
  • Save kaspth/f306e3465371da9a3af27fa2b854253a to your computer and use it in GitHub Desktop.
Save kaspth/f306e3465371da9a3af27fa2b854253a to your computer and use it in GitHub Desktop.
class User
belongs_to :timeline
end
class User::Timeline
has_many :items
end
class User::Timeline::Item
belongs_to :timeline
end
class User::TimelinesController
def show
@items = Current.user.timeline.items.order(:created_at)
end
end
# app/views/user/timelines/show.html.erb
@items.each do |item|
if Current.user.favorite?(item)
button_to unfavorite_item_path(item), method: :delete
else
button_to favorite_item_path(item)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment