Last active
March 21, 2017 17:33
-
-
Save eric1234/19e1e763cdd8f1815e02804483f61368 to your computer and use it in GitHub Desktop.
Example Real Controller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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