Skip to content

Instantly share code, notes, and snippets.

@bunnymatic
Last active Jan 2, 2016
Embed
What would you like to do?
active_model_conversion blog post assets
# the hot stuff wrapper/presenter
class HotStuff
def items
@items ||= Stuff.hot.limit(5)
end
end
/ in app/views/hot_stuffs/_hot_stuff.slim
h1 this is hot
ul.hot_stuff
- @hot_stuff.items.each do |hot|
li = hot.snippet
# in app/controllers/pages_controller.rb
class PagesController < ApplicationController
...
def welcome
@hot_stuff = Stuff.hot.limit(5)
@recent_activity = Activity.recent.limit(5)
...
end
end
def welcome
@hot_stuff = HotStuff.new
@recent_activity = RecentActivity.new
end
# app/controllers/pages_controller.rb
def welcome
@homepage_blocks = [HotStuff.new, RecentActivity.new]
end
/ in app/views/pages/index.slim
.main
section.block
h1 this is hot
ul.hot_stuff
- @hot_stuff.each do |hot|
li = hot.snippet
section.block
h1 this is recent
ul.recent_activity
- @recent_activity.each do |recent|
li = recent.snippet
... etc ...
/ app/pages/index.html.slim
.main
section.block
== render @hot_stuff
section.block
== render @recent_activity
/ app/pages/index.html.slim
.main
section.block
- @homepage_blocks.each do |block|
== render block
# the recent activity wrapper
class RecentActivity
def items
@items ||= Activity.recent.limit(5)
end
end
/ in app/views/recent_activities/_recent_activity.slim
h1 this is recent
ul.recent_activity
- @recent_activity.items.each do |recent|
li = recent.snippet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment