jyoseph
jyoseph

Reputation: 5455

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.

Upvotes: 6

Views: 1069

Answers (1)

Ryan Bigg
Ryan Bigg

Reputation: 107738

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.

Upvotes: 9

Related Questions