resources_controller icon indicating copy to clipboard operation
resources_controller copied to clipboard

Use resource or @resource in before_filter

Open joost opened this issue 13 years ago • 3 comments

Is there a way to use the @resource that is created or the resource method in a before_filter?

joost avatar Apr 21 '11 12:04 joost

I checked a little deeper and found that all actions call find_resource themselves.. instead it would be nice to have a before_filter :find_resource, :only => [:show, :edit, :update, :destroy]

This would make it possible to do some extra checks in a before_filter like:

before_filter :check_if_owner_of_resource

def check_if_owner_of_resource
  redirect_to root_path, :notice => "You are not the owner" unless resource.user == current_user
end

joost avatar Apr 21 '11 13:04 joost

Hi,

I'm currently on holiday until the 1st May. I'll look at this after then.

Cheers, Ian White

Sent from my iPhone

On 21 Apr 2011, at 14:55, [email protected] wrote:

Is there a way to use the @resource that is created or the resource method in a before_filter?

Reply to this email directly or view it on GitHub: https://github.com/ianwhite/resources_controller/issues/4

ianwhite avatar Apr 21 '11 19:04 ianwhite

Any news here? This would be very handy.

noahhaon avatar Jun 14 '11 16:06 noahhaon