How to short the Controller actions in Rails -


def index     @customers = current_user.customers     respond_to |format|       format.html # index.html.erb       format.json { render json: @customers }     end   end    def show     @customer = current_user.customers.find(params[:id])     respond_to |format|       format.html # show.html.erb       format.json { render json: @customer }     end   end    def new     @customer = current_user.customers.new   end 

this little part of customercontroller. origin @customers @customers = customers , on.

i wanted index/show/new current_user. working, had manually change controller actions. , automated spec files testing @customer = customers.

this seems not rails way change of them manually.

is there better solution this?

thanks in advance best regards denym

the rails way tackle using inherited_resources gem in combination responders. use case described in overwriting defaults section of inherited_resources.

this approach discussed in chapter "writing dry controllers responders , generators" in josé valims book crafting rails applications: expert practices everyday rails development.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -