...code comments come into play: Use code comments to document Hows and Whys Group belonging lines with empty lines ("code paragraphs") New code is usually bright and clear to the...

While verifying doubles in RSpec is a good default, it is limited in the amount of methods it actually is...

Debugging your integration tests, that run a headless Chrome inside a docker image, is tricky. In many cases you can...

...move the directory to its new location old_store_path = Pathname.new(old_store_dir) begin FileUtils.rmdir(old_store_path.parent) # cleanup empty directories afterwards rescue Errno::ENOTEMPTY => e # ignore exception for non-empty...

index 0000000..a51cbad --- /dev/null +++ b/app/models/apple.rb @@ -0,0 +1,9 @@ +class Apple < Fruit + belongs_to :juice, class_name: 'AppleJuice' + + attr_accessor :type + + def to_s + I18n.t(type, scope: 'fruits.apples...

index 0000000..a51cbad --- /dev/null +++ b/app/models/pear.rb @@ -0,0 +1,9 @@ +class Pear < Fruit + belongs_to :juice, class_name: 'PearJuice' + + attr_accessor :type + + def to_s + I18n.t(type, scope: 'fruits.pears...

If you want someone to be able to access your rails console, but don't want them to be able...

makandra dev

All browsers implement an event named beforeunload. It is fired when the active window is closed and can be used to display an alert to warn the user about unsaved...

...To trigger the alert, you have to call preventDefault() on the event. Note The beforeunload event is only dispatched when the user navigation makes a full page load, or if...

makandra dev

If you want Sidekiq to be able to talk to Redis on staging and production servers, you need to add...

Programatically invoke Rails generators Require the generator, instantiate it and invoke it (because generators are Thor::Groups, you need...

makandra is responsible for maintaining about 75 Ruby projects. These projects use a large number of different versions for Ruby...

Say you wrap your index view in a form to apply different filters like pagination or a search query. On...

makandra dev
github.com

...large number of ActiveRecord objects only to collect its ID. Edge Rider has a better way. Your relations gain a method #collect_ids that will fetch all IDs in a...

...number of ActiveRecord objects only to collect its column value. Edge Rider has a better way. Your relations gain a method #collect_column that will fetch all column values in...

...the puppetdb_query feature. This can result in more complex code but has several benefits: you can use more complex puppetdb queries to get the resources you want than with...

makandra dev
tpgi.com

These are the top ten accessibility errors as researched by TPGi, a company focusing on accessibility. See the linked article...

When using Chrome for Selenium tests, the chromedriver binary will be used to control Chrome. To debug problems that stem...

In Capistrano 3, your Capfile requires 'capistrano/rails/migrations', which brings two Capistrano tasks: deploy:migrate and deploy:migrating. The former checks...

api.rubyonrails.org

...class Image < ActiveRecord::Base; end class Video < ActiveRecord::Base; end class PageVersion < ActiveRecord::Base belongs_to :primary_medium, polymorphic: true # may be Image or Video end class Page < ActiveRecord::Base...

...belongs_to :current_version, class_name: 'PageVersion' end Now, when you load pages and include their current versions' primary media... Page.includes(:current_version => :primary_medium).to_a ... Rails will produce...

makandra Curriculum

We've already learned how to integrate user-provided images uploads to our application in 205 basic file uploads and...

has_many :images, through: :album_images end # Join model class AlbumImage < ActiveRecord::Base belongs_to :album belongs_to :image end Destroying a record in this setup will only remove...

...the record itself, and leave orphaned join records behind. image = Image.last image.destroy # removes only the `image` record, # but none of the associated `album_image` join records Good

When you don't only have a favicon.ico in your project but also PNGs of different sizes and backgrounds, you...

By default subscript ( ) and superscript ( ) tags are styled with vertical-align: sub, respectively vertical-align: super by most browsers.

makandra Curriculum

How to write an issue Issue format Read the card Project management best practices: Issues. Gatekeeping Get familiar with our Gatekeeping process. In particular you should understand the...

...you obviously do not want to duplicate it and your tests might very well benefit from this approach. Use it with care, however -- doing this more than a few times...

...making the test impossible to read). An alternative is also to hide that functionality behind other steps that do more complex things differently...

...NonExistentClass".constantize # => NameError: uninitialized constant NonExistentClass Dynamic Programming In scenarios where your application’s behavior depends on dynamic constant resolution, safe_constantize may offer a more convenient control flow to...