Skip to content

Instantly share code, notes, and snippets.

@kerinin
Created September 24, 2013 19:02
Show Gist options
  • Save kerinin/6689602 to your computer and use it in GitHub Desktop.
Save kerinin/6689602 to your computer and use it in GitHub Desktop.
class DevelopersController < ApplicationController
respond_to :hal
FILTERS = {
:created_since => ->(p,d) {d.where(:created_at.gte => p.to_i)},
:last_activity_since => ->(p,d) {d.with_last_activity_after(p)},
:email_address => ->(p,d) {d.where(email_address: p)},
:api_key => ->(p,d) {d.where(api_key: p)}
}
def index
@developers = FILTERS.reduce( Developer.page(params[:page] || 1) ) do |developers, filter|
key, f = filter
if params.has_key?( key )
f.call( params[key], developers )
else
developers
end
end
@count = @developers.count
@developers = @developers.per(10)
end
def show
@developer = Developer.where(api_key: params[:id]).first
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment