Skip to content

Instantly share code, notes, and snippets.

@launchkit-codes
Created December 3, 2014 10:26
Show Gist options
  • Select an option

  • Save launchkit-codes/2720aef820a818eb9ad0 to your computer and use it in GitHub Desktop.

Select an option

Save launchkit-codes/2720aef820a818eb9ad0 to your computer and use it in GitHub Desktop.
Sort by ActiveRecord column
# Model
class Item < ActiveRecord::Base
scope :sort_by, ->(attr) { order(attr) }
end
class ItemsController < ApplicationController
def index
@items = Item.sort_by(params[:sort])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment