ActiveStorage does not provide any built-in way of implementing authentication for the available DirectUpload endpoint in Rails. When using...
...are three dimensions you can control when scoping routes: path helpers, URL segments, and controller/view module. scope module: 'module', path: 'url_prefix', as: 'path_helper_name' do resources :examples, only...
...and expose data over events used below. const controller = new CustomDirectUploadController(input, input.files[0]) controller.start(storedInput) } const hasFile = function() { return (storedInput?.value !== undefined && storedInput?.value !== '') || input.value !== '' } const updateClearButton = function() { clearButton.classList.toggle...
Every Rails response has a default ETag header. In theory this would enable caching for multiple requests to the same...
To attach files to your records, you will need a new database column representing the filename of the file...
When you allow file uploads in your app, a user might upload content that hurts other users. Our primary concern...
...abort it manually by using an AbortController: let controller = new AbortController() countDown(10, { signal: controller.signal }).then( () => console.log("10 seconds have passed"), (reason) => console.log("Countdown failed:", reason) ) controller.abort() /* prints "Coundown failed...
If you run a Rails app that is using Turbo, you might observe that your integration tests are unstable depending...
When Paperclip attachments should only be downloadable for selected users, there are three ways to go. The same applies to...
...expected_resource = expected_resource @expected_options = expected_options end def matches?(controller) @controller_class = controller.class @actual_resource = @controller_class.instance_variable_get('@aegis_permissions_resource') @actual_options = @controller_class.instance_variable_get('@aegis_permissions...
Here are some popular mistakes when using nested forms: You are using fields_for instead of form.fields_for.
Rails offers several methods to manage three types of different cookies along with a session storage for cookies. These...
In development, we store files using ActiveStorage's disk service. This means that stored files are served by your Rails...
...specs will mock a lot of rails behavior and render the view independent from the controller-logic. Therefore it will be more applicable to test views within request specs. But...
Rails partials have a lot of "hidden" features and this card describes some non-obvious usages of Rails Partials.
...link[rel*=icon]')?.href || '/favicon.ico' timeout ||= 6000 const controller = new AbortController() const timeoutTimer = setTimeout(() => controller.abort(), timeout); try { await fetch(path, { cache: 'no-store', signal: controller.signal }) return true } catch(error) {
ActiveRecord gives you the :include option to load records and their associations in a fixed number of queries. This is...
All direct child directories of app are automatically added to the eager- and autoload paths. They do NOT create a...
When your Rails application offers downloading a bunch of files as ZIP archive, you basically have two options:
The git doc states on the difference of these two commands: git-restore[1] is about restoring files in the...
...yourself mixing in the same ETag inputs in all actions, you may also use a controller-wide etag {...
class UsersController < ApplicationController etag { current_user } # Mix the current user into...
config.before do # stuff that_fancy_method if is_a? Spec::Rails::Example::ControllerExampleGroup # more stuff end Find out if you are in a spec that knows about request...
By default, browsers will not wrap text at syllable boundaries. Text is wrapped at word boundaries only. This card explains...
1. Saving files to a directory that is not shared between deploys or servers If you save your uploads to...