Develop the right mindset for Rails security
Avoid shipping vulnerable code by learning how to prevent security issues in your Rails applications.
Get the course for $99gem 'actionpack-page_caching'class ApplicationController < ActionController::Base
include ActionController::Caching::Pages
self.page_cache_directory = "#{Rails.root.to_s}/public/page_cache"
endclass ArticleController < ApplicationController
caches_page :index, :show
# Rest of the file omitted.
endupstream puma_server_domain_tld {
server unix:/path/to/the/puma/socket;
}
server {
listen 80;
server_name domain.tld;
root /path/to/the/app;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
# try the $uri, than the uri inside the cache folder, than the puma socket
try_files $uri /page_cache/$uri /page_cache/$uri.html @puma;
}
location @puma{
proxy_pass http://puma_server_domain_tld;
break;
}
# set the expire date to max for assets
location ~ "^/assets/(.*/)*.*-[0-9a-f]{32}.*" {
gzip_static on;
expires max;
add_header Cache-Control public;
}
}gem 'rails-observers'class ArticleSweeper < ActionController::Caching::Sweeper
observe Article
def after_save(record)
expire_page(articles_path)
expire_page("/#{record.url}")
end
end