Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails - Block all but certain IP address

I'm working on a rails 3 app that I would like to temporarily be blocked by all requests not coming from my IP address. What is the best way to go about that?

I figured I could do something at the controller level, but I'm a newb and was not sure what the best practice is.

like image 889
jyoseph Avatar asked Jan 08 '11 04:01

jyoseph


1 Answers

Wrap all your routes in a constraints block:

constraints :ip => "your-ip-goes-here" do
  # routes go here
end

Your Rails app will deny all knowledge of routing if other people try to access this.

This method is really handy if you want to constrain based on other things too, like the iPhone example the documentation shows.

like image 78
Ryan Bigg Avatar answered Oct 18 '22 20:10

Ryan Bigg