Skip to content

Instantly share code, notes, and snippets.

@kevinrutherford
Created May 14, 2013 18:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinrutherford/5578425 to your computer and use it in GitHub Desktop.
Save kevinrutherford/5578425 to your computer and use it in GitHub Desktop.
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