Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rails: put and interruption in before filter

I want a before filter like "must_have_permission_to_write" that when called if user hasn't permission to write renders a message saying "you can't do that!" and return.

Problem is I'm getting "can only render or redirect once per action" of course... how can I stop the execution in the before filter? thanks

like image 375
luca Avatar asked Jun 28 '26 13:06

luca


1 Answers

I think the easiest answer is add a redirect and return false to your must_have_permission_to_write method.

def must_have_permission_to_write
  unless current_user.has_permission?(something)
    redirect_to access_denied_path 
    return false
  end
end

Then, create an action for access denied somewhere, add the route, and put whatever you want in the template.

like image 122
Ben Crouse Avatar answered Jul 01 '26 07:07

Ben Crouse



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!