Skip to content

Instantly share code, notes, and snippets.

@pschyska
Created September 2, 2013 13:55
Show Gist options
  • Save pschyska/6413138 to your computer and use it in GitHub Desktop.
Save pschyska/6413138 to your computer and use it in GitHub Desktop.
class Backend::Settings::TiersController < BackendController
before_filter :authorize_admin
def index
@tiers = current_company.tiers.order('sort ASC')
end
def update
@tier = current_company.tiers.find(params[:id])
old_sort = @tier.sort
@tier.update_attributes(params[:tier])
if @tier.sort_changed?
# search for another tier in this company with the new sort
# if it exists, swap sort values
if other = Tier.where(sort: @tier.sort).first
# FIXME: we have to skip validations here ...
other.update_attribute(:sort, old_sort)
end
end
@tier.save!
p Tier.all
redirect_to action: :index
end
def move_up
end
def move_down
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment