I want the /admin route on my rails app to be protected by using .htaccess password files - is this possible?
相关问题
- Question marks after images and js/css files in ra
- Using :remote => true with hover event
- Backbone.js PushState routes .htaccess only workin
- Stop .htaccess redirect with query string
- Eager-loading association count with Arel (Rails 3
相关文章
- Ruby using wrong version of openssl
- Right way to deploy Rails + Puma + Postgres app to
- AWS S3 in rails - how to set the s3_signature_vers
- Difference between Thread#run and Thread#wakeup?
- how to call a active record named scope with a str
- How to add a JSON column in MySQL with Rails 5 Mig
- “No explicit conversion of Symbol into String” for
- form_for wrong number of arguments in rails 4
Rails has a built-in helper for this, you could place this in your application controller:
Then use a before_filter on any controllers you want to protect (or just stick it in the application controller to block the whole site):
This method works on Nginx as well as Apache, which is an added bonus. It doesn't, however, work if you have full page caching enabled - as the visitor never hits the Rails stack; it won't kick in.
Edit Just noticed that you specified the /admin route. All my admin controllers inherit from an AdminController. You could set yours up like so:
/app/controllers/admin/admin_controller.rb
Then have all your controllers extend the admin controller, eg:
My routes are setup like so:
Hope that helps.