Do not deliver mails when there are no recipients set
When using ActionMailer, you can set an array of email addresses as recipients
. If this array is generated by e.g. collecting email addresses from the database, it might sometimes be empty.
To prevent ActionMailer to deliver mails to nobody, simply overwrite the deliver!
method like this:
# In your mailer.rb
def deliver!(mail = @mail)
return false if (recipients.nil? || recipients.empty?) && (cc.nil? || cc.empty?) && (bcc.nil? || bcc.empty?)
super
end
Related cards:
Async control flow in JavaScript: Promises, Microtasks, async/await
Slides for Henning's talk on Sep 21st 2017.
Understanding sync vs. async control flow
Talking to synchronous (or "blocking") API
print('script start')
html = get('/foo')
print(html)
print('s...
Delivering Carrierwave attachments to authorized users only
Preparation
To attach files to your records, you will need a new database column representing the filename of the file. To do this, add a new migration (rails g migration <name>
) with the following content:
class AddAttachmentToNotes...
JavaScript without jQuery (presentation from 2019-01-21)
Summary
- We want to move away from jQuery in future projects
- Motivations are performance, bundle size and general trends for the web platform.
- The native DOM API is much nicer than it used to be, and we can polyfill the missing pieces
- Un...
What collapsing margins are, how they work and when margins do not collapse
Imagine you have 2 HTML boxes. The first one has a margin-bottom
of let's say 30px
and the second one a margin-top
of 20px
. After rules of collapsing margins have been applied we ha...
When Internet Explorer does not render webfonts on customer machines
Things to check first
- Do you deliver fonts in a format that the target IE version understands?
- Did you double-check your
@font-face
declarations with all the hacky syntax that is required? Compare them with other decl...
Fix external Displays switching not on when plugging notebook in docking station
If your external displays not switching on or showing a weird behavior (for e.g. all displays getting the same configuration all the time) you can fix it by switching off all external displays and re-enabling only one in the first step. Afterwards...
PSA: When Redis (on LRU noeviction) reaches memory limits, keys with (any) expiry are removed, and keys without are not
In production, you (or your ops team) should configure a maximum number of bytes that Redis can use to store data (maxmemory
setting).
They may even want to set maxmemory-policy
to noeviction
to avoid keys being removed that you want to keep...
Exception Notifier: Foreground vs. background sections
Since version 2.6 exception notifier distinguishes between foreground and background sections. The reason is that with background jobs (e.g. methods that are called by a cron job) some variables are not available for exception notifier, e.g. `@req...
How to not leave trailing whitespace (using your editor or Git)
There is no reason to leave trailing whitespace characters in your project's files, so don't add any.
A git diff --check
will tell you if there are any and you should not commit when you see them. So go ahead and switch your editor/IDE to autom...
Heads up: Sidekiq per default silently fails when retries are exhausted!
For Sidekiq to be able to retry your jobs it has to be able to catch errors that occur while a job is executed.
Per default, Sidekiq will not raise / notify you if the retry count is exhausted. It will only copy the job to the dead queue (see...