Skip to content

Instantly share code, notes, and snippets.

@eric1234
Last active March 21, 2017 17:33
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 eric1234/19e1e763cdd8f1815e02804483f61368 to your computer and use it in GitHub Desktop.
Save eric1234/19e1e763cdd8f1815e02804483f61368 to your computer and use it in GitHub Desktop.
Example Real Controller
class Admin::AgentsController < AdminController
include ListParams
include StatusFilter
helper :filter
let(:agents) { policy_scope authorize Agent.all }
let(:agent) { authorize agents.with_stats.find_or_build params[:id] }
def index
self.agents = filter_by_status agents, list_params[:status]
self.agents = agents.search list_params[:q], include_brokerage_name: policy(Brokerage).general? unless list_params[:q].blank?
self.agents = agents.includes :brokerage if policy(Brokerage).modify?
self.agents = agents.with_stats.order(:last_name, :first_name).page list_params[:page]
end
defs :new, :edit do
render 'form'
end
def create
agent.brokerage = current_brokerage unless policy(Brokerage).modify?
update
end
def update
if agent.update params[:agent]
redirect_to edit_admin_agent_path(agent), notice: 'Successfully saved!'
else
render 'form'
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment