ruby-doc.org

...other methods within the Method class are useful for advanced metaprogramming, though this is beyond the scope of this card. Also see Ruby: Finding where a method is defined

developer.mozilla.org

The linked MDN article is quite informative of a neat feature supported by all major browsers: Unicode character class escape...

...many :taggings, dependent: :destroy + has_many :posts, through: :taggings +end app/models/tagging.rb +class Tagging < ApplicationRecord + belongs_to :post + belongs_to :tag + + validates :post, uniqueness: { scope: :tag } +end app/controllers/posts_controller.rb def post_params...

...many :taggings, dependent: :destroy + has_many :posts, through: :taggings +end app/models/tagging.rb +class Tagging < ApplicationRecord + belongs_to :post + belongs_to :tag + + validates :post, uniqueness: { scope: :tag } +end app/controllers/posts_controller.rb def new

...optional on association declarations with a symbol, lambda or proc. Explanation Association declarations like belongs_to support the option optional. This option does not support symbols, lambdas or procs. If...

...the presence of the associated object won't be validated. Example Bad class Note belongs_to :owner, optional: :draft? end note = Note.new(state: 'created', owner: nil) note.valid? # => true Good

track down warnings and to see failing specs immediately or to get an overview of the core...

...by doing date on the shell. E.g. our main application servers are running on Berlin (CEST) time, but this will differ on other machines. Rails also assumes that datetime fields...

...Rails 2, open config/environment.rb and comment or remove the config.time_zone line: # config.time_zone = 'Berlin' In order to disable time zone conversion in Rails 3 or newer, open config/application.rb and...

For performance improvements (and to remove the need for eager loading), the ActsAsTaggableOn gem supports caching your tag lists directly...

...applications is to make the observe frequency low enough that out-of-order responses become unlikely enough. Try to poll the query field for changes every 0.75 seconds or longer...

Ubuntu has a package mysql-sandbox that lets you install multiple MySQL versions into your user home: Install mysql-sandbox...

makandra dev
web.archive.org

When testing your command line application with Aruba, you might need to stub out other binaries you don't want...

When deploying a Rails application that is using Webpacker and Capistrano, there are a few configuration tweaks that optimize the...

...HTML elements can automatically start playing when the autoplay attribute is set on them. Except for when they can not...

Rails has the handy controller method send_file which lets us download files easily. We can decide whether the file...

RSpec lets you define the arguments with which you expect a method to be invoked: subject.should_receive(:say).with('hello...

github.com

Looks simpler than inaction_mailer: gem install mailcatcher mailcatcher Setup Rails to send mails to 127.0.0.1:1025. Usually you want...

When accepting GIF images, you will also accept animated GIFs. Resizing them can be a time-consuming task and will...

Reacting on a class getting added can be done with a mutation observer. Example: const items = document.querySelectorAll('.item') const expectedClass...

When you use a belongs_to or has_many macro you might be surprised that the methods that it generates does not override a method with the same name. Take...

class Project < ActiveRecord::Base def user "foo" end belongs_to :user end Project.new.user still returns "foo". The reason for this is that what belongs_to does is actually...

chrisboakes.com

Debouncing a method call delays its execution until after a specified time has passed. If it's called again before...

makandra dev

...is no longer established using sudo per default. Databases created for local development usually belong to the local user an therefore do not need to be accessed using sudo...

When you do a bitwise copy using the dd tool you will not see any output until it completes or...

The tree command will show you the contents of a directory and all its sub directories as a tree:

Use option:checked to find the currently selected option: select.querySelector('option:checked') Yes, :checked, not :selected. This is the same...

If a Cucumber run deletes your application directory, an integration fail between Capybara and Capybara Screenshot may be the cause...