Bapta Arjun
Bapta Arjun

Reputation: 43

Rails query parameter constraints?

Is there any way I can apply constraints to the query string in Rails routes?

Valid routes: /path/?type=A and /path/?type=B

Any other type should be invalid route. For eg. /path/?type=C should be invalid(400 Bad request)

Upvotes: 2

Views: 518

Answers (1)

SteveTurczyn
SteveTurczyn

Reputation: 36860

You can do this in your action...

def my_action
  raise ActionController::BadRequest unless %w(A B).include?(params[:type])
  ... # normal actions here
end

Upvotes: 2

Related Questions