...the commit which was deployed. If you want to know the currently deployed release, simply SSH to a server and view that file. $ cat /var/www/my-project/current/REVISION cf8734ece3938fc67262ad5e0d4336f820689307 Capistrano task
...application is deployed to multiple servers, you probably want to see a result for all of them. Here is a Capistrano task that checks all servers with the :app role...
When doing some meta-programming magic and you want to do something for all attributes of a class, you may need to access connection or some of its methods (e.g...
...will encounter fun errors such as: PG::ConnectionBad (for missing databases on PostgreSQL) ActiveRecord::StatementInvalid: PG::UndefinedTable (when database exists, but has no tables) Generally speaking, evaluating model columns during...
It's possible to implement simple custom RuboCop cops with very little code. They work exactly the same like existing rubocop cops and fail the pipeline if they find an...
...offense. This is handy for project specific internal rules or conventions. The following cop looks at every ruby file and searches for TODO or WIP comments and adds an offense...
...come across objects created by some gem or framework. You don't have the source code at hand, still need to inspect this object. Here are some tools to do...
...from Object. This makes the methods list drastically more relevant. You can also try subtracting other base classes like ActiveRecord::Base.methods etc. To further narrow it down you can also...
...an event handler, there are multiple methods to cancel event propagation, each with different semantics. event.preventDefault() Only prevents the default browser behavior for the click, i.e. going to a different...
...url or submitting a form. When invoked on a touchstart event, this also prevents mouse events like click to be triggered. event.stopPropagation() Prevents the event from bubbling up the DOM...
...the code below to check whether the browser can make connections to the current site: await isOnline() // resolves to true or false Limitations of navigator.onLine While you can use the...
...built-in function navigator.onLine (sic), it is only a hint for whether the device can access the Internet. When navigator.onLine === false you know for certain that the user device has...
Sometimes you have a file that is related to a project, while not actually being part of it. You'd like to keep them around, but others won't need...
...them – e.g. some notes, a log, or a database dump. Sure, you have a project directory – but all of it is tracked by Git. A project's tmp/ directory is...
Ubuntu 18.04 uses systemd to manage services. There are basically two commands for listing all services and manipulating the state of a certain service: service and systemctl: service manages System...
...which system V init scripts are available and running / not running, you can use service --status-all: >service --status-all [ + ] acpid [ - ] alsa-utils [ - ] anacron [ + ] apache-htcacheclean [ - ] apache2 [ + ] apparmor [ + ] apport
In the past we validate and set default values for boolean attributes in Rails and not the database itself. Reasons for this: Older Rails didn't support database defaults when...
...the Rails upstream on constraints in the database, is adding default values in the schema of the database itself. We also encourage to set boolean attributes to not null. For...
...tell npm to install a package globally with npm -g install @puppeteer/browsers. However, it seems that its not possible that npx can run commands from global packages without referencing the...
...image, where a testing chrome and chromedriver is installed with a global npm package. Since there is no local project it was more useful to install the package in a...
...the cogwheel icon (or press F1 when focusing the dev tools) to open the settings overlay. Under "Preferences", in the "Appearance" section, find the "Panel layout" option. Set it to...
Alternatively, press Ctrl+Shift+P and search for "panel layout". Wat? Vertical means that the DOM tree is next to the styles/etc panel, like so:
Module imports are hoisted (internally moved to the beginning of the current scope). Therefore, it doesn’t matter where you mention them in a module and the following...
Footgun example When you're not aware of import hoisting you may be surprised that your code runs in a different order than you see in the source file...
ActiveSupport (since 4.1) includes test helpers to manipulate time, just like the Timecop gem: To freeze the current time, use freeze_time (ActiveSupport 5.2+): freeze_time To travel to a...
...specific moment in time, use travel_to: travel_to 1.hour.from_now Important When freezing time with #travel_to, time will be frozen (like with freeze_time). This means that your...
...automatically. If you delete records regularly, this may be an annoyance. Here is a solution which was adapted from the Carrierwave GitHub wiki and cleans up any empty parent directories...
class ExampleUploader < CarrierWave::Uploader::Base storage :file after :remove, :remove_empty_container_directory def store_dir # You implemented this in your uploaders already. end def remove_empty...
...not necessary to add a version constraint next to your gems in the Gemfile. Since all versions are saved in the Gemfile.lock, everyone running bundle install will get exactly the...
...You are not checking in the Gemfile.lock into the version control (not recommended) A specific gem has a bug in a more recent version (adding a comment for the reason...
...discouraged to load your JavaScript by a tag in the : The reason is that a tag will pause the DOM parser until the script has loaded and executed. This will delay the browser's first contentful paint. A much better default is to load your scripts with a tag: A deferred script has many useful properties: It does not block the browser from rendering content. Deferred scripts...
...can query the entire DOM tree with querySelector() and friends. document.readyState is 'interactive'. Deferred scripts will run before the DOMContentLoaded event. That means if your code waits to initialize until...
...posts; if you use pagination the queries will be more complicated, but the point still stands. Looks harmless enough? It is not. The problem ActiveRecord will rewrite this into a...
...query using LEFT JOINs which looks something like this: SELECT "blog_posts".*, "comments".*, "attachments".* FROM "blog_posts" LEFT OUTER JOIN "comments" ON "comments"."blog_post_id" = "blog_posts"."id"
By default, Devise sends all emails synchronously with deliver_now. To change that, Devise's readme suggests overwriting the send_devise_notification method like this: class User def send_devise...
...notification(notification, *args) devise_mailer.send(notification, self, *args).deliver_later end end However, there is one problem: When deliver_later enqueues the mail with ActiveJob, the job arguments are logged. In...
There is a practical short list for valid/invalid example email addresses - Thanks to Florian L.! The definition for valid emails (RFC 5322) can be unhandy for some reasons, though.
...provides a built-in email regex URI::MailTo::EMAIL_REGEXP. That's the best solution to work with. /\A[a-zA-Z0-9.!\#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0...
...that's not a float! This occurs because JavaScript uses double precision floats to store numbers. So according to IEEE floating point definition only numbers between...
...and 2^53 - 1 (9007199254740991) can safely be represented in JavaScript. Note that ECMAScript 6 will probably also offer Number.MAX_SAFE_INTEGER (and Number.MAX_SAFE_INTEGER) that point to those...
The change_column method for rails migrations support casting with a custom SQL statement. This allows us to change a column type and keep the former content as the new...
...number, 'int USING CAST(rating AS int)' end end Warning This migration's rollback strategy will fail, if any existing entry can't be casted. This is likely to happen...
...to lock a user in devise. Using the lockable module Customizing the user account status validation when logging in. It depends on your requirements which methods works best.
...user on soft delete We recommend to use option 2 when you want to couple the lock to the model's soft delete logic. Option 1 might also work when...
When your public-facing application has a longer downtime for server maintenance or long migrations, it's nice to setup a maintenance page to inform your users. When delivering the...
...maintenance page, be very careful to send the correct HTTP status code. Sending the wrong status code might get you kicked out of Google, or undo years of SEO work...
If you migrate a Rails application from Sprockets to Webpack(er), you can either transpile your CoffeeScript files to JavaScript or integrate a CoffeeScript compiler to your new process. This...
...to the global namespace, define them on window directly: -class @User +class window.User Replace Sprocket's require statement with Webpacker's import statement to load dependencies. -#= require ./person +import './person...