Using the Ruby block shortcut with arguments

Posted Almost 6 years ago by Dominik Schöler.
stackoverflow.com

Ruby has this handy block shortcut map(&:to_i) for map { |x| x.to_i }. However, it is limited to argument...

Rails: Including HTML in your i18n locales

Posted About 6 years ago by Dominik Schöler.
guides.rubyonrails.org

TL;DR Append your locale keys with _html to have them marked as html_safe and translate them with = t...

Capistrano task to tail remote application logs of multiple servers

Posted About 6 years ago by Arne Hartherz.

When your application is running on a multi-server setup, application logs are stored per server (unless you choose a...

Unpoly: Loading large libraries on-demand

Posted About 6 years ago by Henning Koch.

When your JavaScript bundle is so massive that you cannot load it all up front, I would recommend to load...

jQuery: How to replace DOM nodes with their contents

Posted About 6 years ago by Arne Hartherz.

You know that you can use jQuery's text() to get an element's contents without any tags.

When you want to format only line breaks, you probably do not want `simple_format`

Posted About 6 years ago by Arne Hartherz.

For outputting a given String in HTML, you mostly want to replace line breaks with or tags.

Rails: How to provide a public link in a mail

Posted About 6 years ago by Emanuel.

Lets say we have a user with a contract whereas contract is a mounted carrierwave file. Now we want to...

Generating test images on the fly via JavaScript or Ruby

Posted About 6 years ago by Arne Hartherz.
jsfiddle.net

When you need test images, instead of using services like lorempixel or placehold.it you may generate test images yourself.

Rails: Overriding view templates under certain conditions only

Posted About 6 years ago by Dominik Schöler.
api.rubyonrails.org

Rails offers a way to prepend (or append) view paths for the current request. This way, you can make the...

Writing strings as Carrierwave uploads

Posted About 6 years ago by Arne Hartherz.

When you have string contents (e.g. a generated binary stream, or data from a remote source) that you want to...

HTML5: disabled vs. readonly form fields

Posted About 6 years ago by Natalie Zeumann.

Form fields can be rendered as noneditable by setting the disabled or the readonly attribute. Be aware of the differences...

Chrome: Making high-resolution website screenshots without add-ons

Posted Over 6 years ago by Henning Koch.

If you want to make a screenshot of a website that works well in print or on a high-DPI...

XHR is not JSON

Posted Over 6 years ago by Arne Hartherz.

When a Rails controller action should handle both HTML and JSON responses, do not use request.xhr? to decide that. Use...

Carrierwave: Deleting files outside of forms

Posted Over 6 years ago by Dominik Schöler.

TL;DR Use user.update!(remove_avatar: true) to delete attachments outside of forms. This will have the same behavior as...

Form letters with LibreOffice Writer

Posted Over 6 years ago by Henning Koch.

This is painful. Consider using Microsoft Office or switching careers. If you need to write < 20 letters consider doing it...

How to use cookies with curl

Posted Over 6 years ago by Arne Hartherz.
curl.haxx.se

When making requests using curl, no cookies are sent or stored by default. However, you can tell curl to re...

Rails: Migration helper for inserting records without using models

Posted Over 6 years ago by Dominik Schöler.

You should avoid using application models in your migrations. But how else could you create records in a migration?

How to fix HTML elements being cut off when printing

Posted Over 6 years ago by Arne Hartherz.

When you print (or print preview) and elements are cut off (e.g. after 1st page, or "randomly") you should check...

HTML: Making browsers wrap long words

Posted Over 6 years ago by Henning Koch.

By default, browsers will not wrap text at syllable boundaries. Text is wrapped at word boundaries only. This card explains...

chromedriver-helper gem in Gemfile might break you selenium tests (of other projects)

Posted Over 6 years ago by Emanuel.

Summary: Don't add chromedriver-helper to the Gemfile the executables might break your tests in projects where chromedriver-helper...

How to install packages from newer Ubuntu releases

Posted Over 6 years ago by Florian Heinle.

We're usually running Ubuntu LTS versions. Sometimes newer hardware requires packages from more recent Ubuntu releases that only come...

JavaScript: Testing the type of a value

Posted Over 6 years ago by Henning Koch.

Checking if a JavaScript value is of a given type can be very confusing: There are two operators typeof and...

Fixing flaky E2E tests

Posted Over 6 years ago by Henning Koch.

An end-to-end test (E2E test) is a script that remote-controls a web browser with tools like Selenium...

Be careful to use correct HTTP status codes for maintenance pages

Posted Over 6 years ago by Henning Koch.

When your public-facing application has a longer downtime for server maintenance or long migrations, it's nice to setup...