Haml lets you use square brackets (
) to generate a unique class name and ID from a given Ruby object. Haml will infer a
class attribute from the given object's Ruby class. It will also infer an
id attribute from the given object's Ruby class and
This is especially useful with ActiveRecord instances, which have a persisted
#id and will hence generated the same selector ov…
Cookies have an optional
secure flag. It tells the browser to not send the cookie for a non-https request.
It used to be important to activate the
secure flag even on sites that automatically redirect users from
https://. The reason was that most users will only enter a scheme-less domain like
makandra.de into their location bar, which will default to `http://m…
The 90s are calling: they want their tables back. Unfortunately, you'll need them all for laying out your HTML emails. (It is really that bad.)
Email client HTML rendering is way more scattered than browser HTML. While you might have a pretty good understanding of what features and patterns you can use to support all major browsers, I doubt anyone masters this craft for HTML email clients.
The only way to ensure your email looks good (acceptable, at least) in all mail clients, is to check it. Litmus is your go-to solu…
Since late 2015, all major browsers (still excluding Firefox) support pointing device media queries. These can be used to distinguish e.g. coarse from fine pointers (e.g. finger vs mouse), or a device with hover support from one without (e.g. desktop with mouse vs tablet).
When hover styles modify the DOM, most mobile devices activate the hover styles on first tap. A second tap is required to trigger a
click. While this can be handy, at times it makes the UX worse.
Another issue with hover styles is that they tend to st…
Note: Modern Rails has two build pipelines, the asset pipeline (or "Sprockets") and Webpacker. The principles below apply for both, but the examples shown are for Sprockets.
Authentication is hard: there are many edge cases, and most users (including yourself) usually only go the "happy path" once and never see the edge cases. If you have rolled your own authentication, or been using older authentication solutions, or resorted to HTTP Basic Authentication, this card will tell you what to do to make your application safe.
That is: cookies, e.g. by offering a login.
UglifyJS options should only happen in
UglifyjS is only available in production environment. Otherwise you will get a
Error: Item UglifyJs not found when starting a rails server for development.
Note: rake tasks like
NODE_ENV=production whereas starting the rails server has
NODE_ENV=development configured. So you will not get the error on compiling via rake.
Safari on iOS accepts an
apple-touch-icon favicon that is used for stuff like desktop bookmarks. Always define a solid background color for them.
If you use PNGs with a transparent background, Safari will use just set a black background on your pretty icon. This is almost never what you want.
You can fix that by applying a white background via ImageMagick like this:
Please read this article!
This is an extract of the example in the article which demonstrates the execution order of tasks and microtasks.
Here is how to model basic logic in media queries.
# Target viewport widths between 500 and 800px @media (min-width: 500px) and (max-width: 800px)
# Target viewport widths below 500 or above 800px @media (max-width: 500px), (min-width: 800px)
Needs a little overhead with
not all and.
# Target devices that can't hover @media not all and (hover)
See CSS: Using interaction media detection on why you'd need this.
Browsers' printing methods usually don't print background colors. In most cases this is the desired behavior, because you don't want to spent tons of ink printing the background of a web page. But in some cases you want to print the background color of elements, e.g. bars of a chart. For those elements you need to set the following css styles:
There is a kinda secret, yet well supported CSS feature called
currentColor. It's like a special CSS variable that has been supported in almost all browsers for almost all time (see linked Caniuse).
currentColor value can be used in CSS to indicate the current value of
color should be used. A common use case is setting a border color:
a.ghost color: white border: 1px solid currentColor &:hover color: red // Border color will change as well
Note that in many cases, you can simply omit the color to ac…
Google Tag Manager (GTM) is a related tool, but on a higher level and thus with much more power. GTM is not a replacement for GA. Rather, it can make GA configurable without changing anything in the application's code base (and much more beyond, see below).
Only prefer GTM if the customer requests it, or if he is updating his tracking r…
Rails has a default mechanism to store the session in the
CookieStore. This is a cookie which holds the entire user session hash in the browser. This cookie is serialized, encoded with base64, and signed.
Devise uses this
CookieStore. To track a users session, a salt is stored in the session cookie when a user logs in.
When a user logs out this CookieStore is overwrit…
These steps are now part of Spreewald.
Here are some useful examples how to use the attached Cucumber Timecop steps:
When the date is 2011-05-06 When the time is 2011-05-06 17:30
There is also one really awesome step that lets you travel to the past or to the future:
When /^it is (\d+|a|some) (seconds?|minutes?|hours?|days?|months?|years?) (later|earlier)$/
As you can see, you describe the *time unit amo…
The attached patch lets you find a record by a string or number in any column:
User.find_by_anything('carla') User.find_by_anything('email@example.com') User.find_by_anything(10023)
There's also a bang variant that raises
ActiveRecord::NotFound if no record matches the given value:
Boolean and binary columns are excluded from the search because that would be crazy.
I recommend copying the attachment to
features/support/find_by_anything.rb, since it is most useful in Cucumber step …
This card existed before, but was outdated due to browser implementation changes. The information below is validated for the current list of browsers we support.
By default your
body elements are only as high as the actual page content. If you only have two lines of text in your page, your
body elements will only be around 40 pixels high, regardless of the size of your browser window.
You might be surprised by this, since setting a
background on either
body does cover the enti…
One popular strategy to improve the website performance is to not load images until they enter the viewport – aka "lazy-loading images".