api.rubyonrails.org

...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...

...you add conditions on an association that owns polymorphic associations which you want to include. For example, the following raises an error. Page.includes(:current_version => :primary_medium).order('page_versions.updated_at...

...do so by using Consul, but you may use any other mechanisms. class Power include Consul::Power def initialize(user) @user = user end def signed_in? user.present? end power :direct...

Now we define our custom controller using this power: class CustomDirectUploadsController < ActiveStorage::DirectUploadsController include Consul::Controller current_power { Power.new(Current.user) } require_power_check power :direct_uploads end

...small enough to stay fast even on slower mobile connections. Ideally the total size including assets should be < 300 KB on first load (YMMV). Favicon Most mobile devices can add...

...If your web application has shareable content, you can even improve its display by including dynamic meta information with each page. Twitter Cards Facebook's Open Graph. Add these tags...

...Each platform-specific variant ships pre-built binaries of libxml2, e.g. x86_64-linux includes binaries for 64bit Linux on Intel/AMD. This significantly speeds up installation of the gem, as...

...force_ruby_platform option for the gem. This will download the ruby variant which includes no binaries, only the libxml2 extension source. gem 'nokogiri', force_ruby_platform: true

...it needs to skip those children that are #marked_for_destruction?. Otherwise you will include children that have been ticked for deletion in a nested form. Wrong way

...and_store_amount # the critical code 2/2 private def calculate_and_store_amount # may include amounts of items you marked for destruction self.amount = invoice_items.collect(&:amount).sum end end

...existing class from your application. A common use case ist testing modules which are included elsewhere. Your module may behave differently depending on the including class, be parameterized (like with...

While you could test that by using a domain-logic class that currently includes your module, said class may evolve at some point and could brake your tests.

def sanitize_html self.html = Sanitize.clean(html) end end end # app/models/page.rb class Page < ApplicationRecord include DoesSanitizeHtml end # app/models/template.rb class Template < ApplicationRecord include DoesSanitizeHtml end Testing test trait usage with a...

SVG files often contain redundant information, like editor metadata or hidden elements. When esbuild handles your static assets, you can...

github.com

...published for educational purposes on GitHub. The german bachelor's thesis has also been included for download at the end. This card is roughly structured as follows: 1. Research approach...

Combinations of methods For brevity and concise demonstration of the results I only include a introduction to the coverage based TCP. Coverage based TCP Coverage is a metric to...

...is Function.prototype, not Object. Exercise: Multiple inheritance Ruby supports multiple inheritance through modules and include: module Loggable def log(message) let prefix = "[" + self.class.name + "] " puts prefix + message end end

puts "this is foo" end end class Bar < Foo include Loggable def bar puts "this is bar" end end bar = Bar.new bar.foo # prints "this is foo" bar.bar # prints...

...not_change(contract, :attr_2) end end RSpec::Matchers.define_negated_matcher :an_array_excluding, :include describe 'A negated matcher' do it 'can be used in a composed matcher expression' do...

...change { list }.to(an_array_excluding(5)) end end RSpec::Matchers.define_negated_matcher :exclude, :include describe 'A negated matcher' do it 'can be used for creating more expressive and meaningful...

makandra dev
rubydoc.info

...Let's say you have an Uploader like this: class MyUploader < CarrierWave::Uploader::Base include CarrierWave::MiniMagick # Create different versions of your uploaded files: version :small do process resize_to...

...check the dimensions of the several versions by writing RSpec.describe Movie, type: :model do include CarrierWave::Test::Matchers describe '#poster' do before do @movie = create(:movie) @movie.poster.store!(File.open('spec/fixtures/test_poster.jpg'))

github.com

...your worker explicitly with a sidekiq_retries_exhausted-block, e.g. like this: class DownloadWorker include Sidekiq::Worker # Import jobs are retried a few times without sending exception notifications. # Only after...

...expected and the retries total duration fits. # Example: TestWorker.perform_async('foo', 'bar') class TestWorker include Sidekiq::Worker def perform(*args) raise 'This is a test error. All is well.'

thegnar.com

expect(link_element).to have_selector('.nav-link') Info Even though require 'capybara/rspec' includes Capybara::RSpecMatchers by default, such that rendered is converted once one of Capybara's matchers...

...you will might not notice this on your view specs! View helpers are not included by defaulft Helpers used within your view are not included by default. Thus, you may...

relishapp.com

...the ones tagged with speed: 'slow' You can use the tags for hooks and includes, too. RSpec.configure do |config| config.before(:each, slow: true) do # Do one thing here end

...do use TypeScript): { "compilerOptions": { "baseUrl": "./app/assets", "paths": { "@/*": ["js/*"], "@images/*": ["images/*"], "@css/*": ["css/*"], "@spec/*": ["../../spec/js/*"] } }, "include": [] } (The include: [] only makes sense if you do not use Typescript. If you leave it...

...you manually have to update and push them into your repository. The following card includes an option how you can keep them consistently up to date with no extra effort...

...issues. Even if don't set the options above as a default this section includes some useful practical ways on how to correctly record the logs without side effects.

ActiveRecord gives you the :include option to load records and their associations in a fixed number of queries. This is called preloading or eager loading associations. By preloading associations you...

...problem that slows down a many index view. You might have noticed that using :include randomly seems to do one of the following: Execute one query per involved table with...

...wanted to also have access to Rails validations and reached for this: class Address include ActiveModel::API include ActiveModel::Attributes include ActiveModel::Validations REQUIRED_ATTRIBUTES = %i[street_and_number zip...

...option, you can provide a mapping between the attribute names on Address and the including model. However, using that option suddenly switches the way how Rails constructs your Address instance...

...the PostgreSQL server doesn't matter here. For example, the official Ubuntu 20.04 sources include only PostgreSQL 12, so your pg_restore version will also be v12. Ubuntu 22.04 includes...

sudo apt install postgresql-client-16 installs only the PG 16 client, including version 16 of pg_restore sudo apt install postgresql-16 installs PG 16 server and...

...Sprockets) does not seem to be affected by this issue, as every generated file includes a BOM. The first rule above is fulfilled. You can check if a file has...

...a BOM with the file command, e.g. file styles.css should include the text "(with BOM)". Webpack Webpack does not include a BOM per default. Adding the unpopular library webpack-utf8...

validates_attachment_presence :attachment validates_format_of :attachment_file_name, :with => /^\d+\.jpg$/ include DoesCopyErrors[from: :attachment_file_name, to: :attachment] end If you'd like to remove the...

...once they are copied to the target attribute, you can use the :move option: include DoesCopyErors[from: :attachment_file_name, to: :attachment, move: true...

...valid_content_type errors.add(:portrait, "is an invalid file type") unless %w(image/jpeg image/png).include? file.sanitized_file.content_type end end class ImageUploader < BaseUploader end This works perfectly fine, but now every...

In the discussion of the difference between include and extend in Ruby, there is a misconception that extend would add methods to the singleton class of a ruby object as...

...module ClassMethods def foo puts "Foo!" super end end end class User singleton_class.include(A) include B end User.instance_eval do def foo puts 'Foo' super end end User.foo # => "Foo Foo...