Rails3 - How to execute 403 in before_filter without DoubleRender error

I have a before_filter that validates an API key. If the key is invalid, I would like to process the response only on the 403 header.

In my controller:

before_filter :validate_api ... def validate_api if params[:api_key].present? and ApiKey.find(params[:api_key]) return true else render head :forbidden end end 

The problem is that I get a DoubleRender error, presumably when Rails goes into action and tries to display the response anyway. As far as I understand, Rails prevents the action from executing if before_filter displays or redirects. Is that not so?

How to visualize the response only for the header in the before_filter file and prevent the execution of actions?

+6
source share
1 answer

Have you tried to return false in the else part?

+12
source

Source: https://habr.com/ru/post/901237/


All Articles