ruby on rails - How to restrict edit action to only current user -


how can make user edit action available if user current user? using devise.

devise has this:

before_action :authenticate_user!, only: [:new, :edit, :update, :destroy], notice: 'you must sign in first!' 

but make sure user logged in not if user equal current user? want make sure other users aren't able edit other users accounts.

what best way this? should create new before_filter? couldn't find standard way.

you can use current_user method provided devise. here can read more -current_user method.

def edit   unless current_user      redirect_to home_path, :alert => "restricted area"    end end 

Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -