1

How to send error response in ruby if any invalid host requests web server.

As we do in java like below,

response.sendError(HttpServletResponse.SC_BAD_REQUEST, "InValid Host");

Can any one help me out here?

1 Answer 1

1

Since you tagged it with Ruby on Rails I'm going to pass you the Rails method.

# in controller
render plain: 'InValid Host', status: :bad_request

# if you prefer a json response you might want to do
render json: {error: 'InValid Host'}, status: :bad_request

Check out the Rails Guide about this subject: Layouts and Rendering in Rails

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.