When selecting records in a date range, take care not to do it like this: start_date = Date.parse('2007-05...

Sometimes you need to remove high Unicode characters from a string, so all characters have a code point between 0...

...never influence each other On a similar note, we don't want tests to behave differently based on their execution order or parallelism. One core mechanism in this regard is...

...give your Movie model a #person attribute. Instead, use FactoryBot's transient attributes and before/after hooks to implement the factory above...

Resources Rails Guide: Internationalization API Guide to localizing a Rails application Locale-aware helpers in ActionView::Helpers::NumberHelper

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

You cannot use Array#join on an array of strings where some strings are html_safe and others are not...

geekytidbits.com

To retrieve only unique combinations of the selected attributes: You can omit rows, where all selected columns are equal with...

linux.die.net

You can convert git commits into patch files. Those can be used to apply to a different repository [1] or...

makandra dev
github.com

...rendering quality is now fine in recent versions of wkhtmltopdf (0.12+). You will never beat LaTeX if you need perfect font rendering. If you are observing strange behavior when including...

...might experience that your application "locks up" whenever you request a .pdf route. This behavior is caused by a deadlock: The Rails process is trying to render the page to...

...won't need this for single lines of text. In this case it is better to just use the text-overflow property: Use CSS "text-overflow" to truncate long texts...

...starts wrapping within its container. This is most probably because there is no defined behavior in case multiple text contents are rendered next to each other (horizontally) and the clamping...

makandra dev

Note netstat has mostly been superseeded by its more modern rewrite ss which nowadays comes pre-installed rather than netstat...

Developing or debugging SAML functionality can be a hassle, especially when you need to go back and forth with someone...

def self.acquire(name) already_acquired = definitely_acquired?(name) if already_acquired yield else begin create(:name => name) unless find_by_name(name) rescue ActiveRecord::StatementInvalid # concurrent create is okay...

begin result = nil transaction do find_by_name(name, :lock => true) # this is the call that will block acquired_lock(name) result = yield end result ensure maybe_released_lock...

This is a small example on how you can check if your Postgres index can be used by a specific...

makandra dev

For webpages to load fast it's recommended to optimize images. Ideally an image's file size should be as...

Why secure-only cookies used to be necessary Cookies have an optional secure flag. It tells the browser to not...

...used when you are working on a branch and make a new commits which belongs to a previous commit. If the previous commit is the last commit, you can also...

Even though the process in #1 could be used for this it can become quite tedious if you have a large commit and might have already done this and...

...E.g. although an "address book contact" and a "user" are both human beings, it's rarely practical to have them share a model or inheritance hierarchy. Try to model everything...

...CRUD for stands Everything related to viewing and editing weekly reports Read Project management best practices: Issues on how we write user stories. Note that in practice we would do...

In a project team for a bigger project people have several roles: Developer: at makandra Project lead: at makandra

makandra Curriculum

...addresses = AddressBook.new addresses.add Contact.new(first_name: 'Frederik', last_name: 'Foo') addresses.add Contact.new(first_name: 'Berta', last_name: 'Beispiel', phone: '556677') addresses.add Contact.new(first_name: 'Anna', last_name: 'Muster', street: 'Foo...

...returns contacts that match all of the words in any property: results = addresses.search('77 berta') results.size # => 1 results[0].first_name # => "Berta" Errors Change the AddressBook class so the #add...

This still relies on params[:id] existing, so your code should reflect that: # Better User.find(params.expect(:id)) # Or User.find(params.require(:id)) Avoiding issues with extra parameters Rails logs extra...

...should still use permit (or expect) to receive Strong Parameters, but strip extra parameters. # Better (option 1) redirect_to users_path(params.slice(:query, :encoding).permit(:query, :encoding)) # Better (option...

When you want to group rails models of a logical context, namespaces are your friend. However, if you have a...

You want to use fields in your applications. However, your desktop users may encounter some weird quirks: Aside from allowing...

...addition of both margins takes place but the maximum of both is applied. This behavior is called collapsing margins. Oftentimes it is a good behavior but collapsing margins can be...

...the previous sibling of the parent box. Nevertheless there are some exceptions where the behavior of vertical collapsing margins is not used. Exceptions when margins do not collapse