For example, what if I only want those with a certain IP addr (company IP or campus IP etc) to be able to access certain pages? How do I get the visitor's IP and render different pages in different cases?
Asked
Active
Viewed 444 times
0
-
You can rewrite the htaccess rule to achieve this: http://stackoverflow.com/questions/8985502/htaccess-redirect-to-all-ips-but-mine – karthikr Mar 28 '13 at 20:58
2 Answers
0
What server do you have?
Can you use .htaccess files? If yes this is the answer.

Yoni Hassin
- 584
- 1
- 5
- 17
-
Do you mean localhost? The correct way to do what you described is via the .htaccess file(s). The problem is that not all shared servers providers will give you access to that file, that is why you need to verify you will have access to the .htaccess file before relying on it. Search ".htaccess tutrial" on google for further information about the usage of that file. – Yoni Hassin Mar 28 '13 at 21:00
0
Within the context of a controller action, request.remote_ip
will give you the information that you're looking for.
http://apidock.com/rails/ActionDispatch/Request/remote_ip
You could add a filter action to your application controller that renders an error page except when the remote_ip is in a whitelist, for example.

Fitzsimmons
- 1,411
- 1
- 10
- 17