...development PCs so we can operate multiple versions of Node.js in parallel. To make sure that all developers use a compatible version of Node.js, your Rails project should declare the...
...Node version as you cd into a directory. We have a card about automatically switch version when changing directories which provides a solution that works very well for us.
...s e-mails for issues that might cause e-mails to be classified as spam. They provide a one-time e-mail addresses that you can use to sign up...
...etc. You can then check for scoring results of SpamAssassin and other potential issues. You don't need to hit 10/10. Something around 9/10 is perfectly fine. Note:
text The browser will think you wrote invalid HTML by accident, and will sometimes reorder elements silently. There is one notable exception: It's OK to wrap block elements...
...in a tag in HTML5 (not 4). The spec says: The a element may be wrapped around entire paragraphs, lists, tables, and so forth, even entire sections, so long as...
Percent Notation We already know that that we can create strings using the percent notation: %(<foo="bar's ton">) is perfectly fine Ruby. Modifier But there is more. The curly...
...brackets ({}) are interchangable with most unicode characters (e.g. square brackets[]). Furthermore, you can add a "modifier" to the percent notation to control the return type of the expression:
...Actual error: milliseconds differ Note that while the {} vs instance_of(Hash) oddity shows up in the diff, it is not treated as an error. As soon as the millisecond...
...offset is fixed (see this card for details), the spec will pass. Keep this in mind and don't trust RSpec's diffs too much...
...index is not as global as you might think. Actually, it is scoped to a so-called "stacking context". z-indexes only have meaning within their stacking context, while stacking...
...contexts are treated as a single unit in their parent stacking context. This means indices like 99999 should never actually be needed. Creating a new stacking context
Ruby has a set of methods to convert an object to another representation. Most of them come in explicit and implicit flavor. explicit implicit to_a to_ary
to_s to_str to_i to_int There may be even more. Don't name your methods like the implicit version (most prominently to_hash) but the...
Turns out, Cucumber::MultilineArgument::DataTable#diff! caches some stuff. Code of the following form will not work as intended: Then('some table should look like') do |expected_table| patiently do...
...actually patient, will keep failing if it failed the first time end end Instead, simply use expected_table.dup.diff!(actual_table...
...you can use reset: user.posts.reset # discards cache, but does not load anything yet user.posts # SQL query happens to load new state # => [...] Note that reset returns the association/scope. Hence, the above...
...will not seem to work on the Rails console, just because the return value is inspected and thus resolved right away. Try it like this: user.posts.reset; nil # no query
...tools in the Chrome JavaScript console. Make the whole page editable This is not special to Chrome, but still a clever thing: document.body.contentEditable=true Taking time You can easily measure...
...the time on the console with named timers: console.time('myTime'); // Start timer console.timeEnd('myTime'); // End timer and print the time Reference previously inspected elements (from the Elements panel)
In development, we store files using ActiveStorage's disk service. This means that stored files are served by your Rails application, and every request to a file results in (at...
...to disable those log entries. Example Here is an example of what loading a single in an example application writes to the Rails log. Started GET "/rails/active_storage/blobs/redirect/..." for ::1 at...
...text option were able to find nodes based on rendered text, even if it spans over multiple elements in the HTML. Imagine a page that includes this HTML: Hi!
Even though the text is separated by a tag in the HTML, it is matched until Capybara 2 which used to "squish" text prior to the comparison...
...utilities provided are query methods, user interactions, dom expectations and interacting with components of several frontend frameworks, which allows us to worry less about the details happening in the browser...
...find a necessity to use methods like waitFor, because your code itself may trigger something asynchronous (e.g. animations or setTimeout). Let's see what the docs state on this method...
To retrieve only unique combinations of the selected attributes: You can omit rows, where all selected columns are equal with the DISTINCT statement. To retrieve the group wise maximum of...
...columns: You can keep only one record for each group with the DISTINCT ON statement, to omit equal rows within each specified group. Use case You have a query where...
Do you remember finding where a method is defined? I recently learned from a senior colleague that Method objects are quite useful within a debugging feast to find out the...
...they are either called within the current context or because you want to learn something about the API of the current objects. Why is this useful? This is especially useful...
...op]=-operators work the same way, but actually they don't. ||= and &&= Those are special cases, because the assignment will only happen if the first variable passes the check (false...
...and true for &&). a ||= b # => a || (a = b) a &&= b # => a && (a = b) But still, if reading a has any side effects, they will take place regardless of to what...
Access the Method object Dead simple: Get the method object and ask for its owner: "foo".method(:upcase) # => # "foo".method(:upcase).owner # => String Look up a method's source location...
...Ruby 1.9 adds a method Method#source_location that returns file and line number where that method is defined. class Example; def method() end; end # => nil Example.new.method(:method).source_location...
Using ffmpeg, you can easily re-encode a video to reduce its file size. Command Do it like this: ffmpeg -i input.mp4 -c:v libx264 -crf 23 -preset slow -c...
...a copy -movflags +faststart output.mp4 Arguments -i input.mp4 specifies your input file -c:v libx264 specifies H.264 encoding. Use -c:v libx265 for H.265/HEVC. It's an excellent modern encoding...
For Selenium tests, your browser starts in your local timezone, or whatever your system's environment specifies. This is usually good enough. To test any timezone-dependent behavior in Chrome...
page.driver.browser.execute_cdp('Emulation.setTimezoneOverride', timezoneId: 'Asia/Tokyo') Important: This change is permanent throughout the browser session. You need to remove the time zone override at the end of each test explicitly...
...extend in Ruby, there is a misconception that extend would add methods to the singleton class of a ruby object as stated in many posts on this topic. But in...
...fact, it is added to the ancestors chain of the singleton class! Even though it is technically not the same, practically this can be considered the same in most use...
+:name => "Foo", +:thread => {:id=>1, :title=>"Bar"}, Instead you need to do something like this: describe 'user' do let(:user) { {id: 1, name: 'Foo', thread: {id: 1, title...
...relation you have to map the attributes and mutate for indifferent access or use string hash keys users.map(&:attributes).to include(hash_including('name' => 'Some name...
...front of our eyes and humans consume PDF content all the time with great success. Why would it be difficult to automatically extract the text data? Turns out, much how...
PostgreSQL offers a really handy field type: json. You can store any JSON there, in any structure. While its flexibility is great, there is no syntactic sugar in Rails yet...
...returns JSON, whereas ->> returns text. Note that the key(s) must be passed with single quotes. Updating records is not supported for json columns. jsonb columns can be updated, but...
...how to make fixes in other people's GitHub repositories. It's basically "Open Source Development 101". Way back in mid-2007, when Rails 1.2 was the new hotness and...
...GitHub was still a year away from crawling out of the primordial internet soup, prolific open source contributor Dr Nic wrote an article titled “8 steps for fixing other people...