Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Query actions in Rails contollers
class ApplicationController < ActionController
def wiki
@wiki ||= if (current_user.admin?)
AdminWiki.new
else
ReadonlyWiki.new
end
end
end
class CardsController < ApplicationController
def recently_changed
render 'recently_changed', locals: {
cards: RecentlyChanged.new(wiki).cards,
}
end
end
class StatisticsController < ApplicationController
def traffic
hits_by_date = statistics.page_hits_by_date
render 'traffic', locals: {
weekly_page_hits: statistics.weekly_page_hits(hits_by_date),
weekday_hits: statistics.hits_by_weekday(hits_by_date),
time_of_day_hits: statistics.hits_by_time_of_day,
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment