Skip to content

Instantly share code, notes, and snippets.

@pier-oliviert
Created December 8, 2014 14:32
Show Gist options
  • Select an option

  • Save pier-oliviert/21da1357b7d69a7fa8a3 to your computer and use it in GitHub Desktop.

Select an option

Save pier-oliviert/21da1357b7d69a7fa8a3 to your computer and use it in GitHub Desktop.
class FollowersController < ApplicationController
before_action :authenticate!
def index
@pictures = current_user.followers.pictures
end
end
class Picture < ActiveRecord::Base
scope :filter do |type|
case type
when 'hot'
where('some SQL mumbo jumbo')
when 'recent'
order('pictures.created_at DESC')
end
end
end
class PicturesController < ApplicationController
before_action :authenticate!
#If a user is a guess, it redirects here.
def index
@pictures = Picture.filter(params.fetch(:f, 'all'))
end
end
YourApp.routes.draw do
resources :pictures
resources :followers
root to: 'pictures#index'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment