...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...
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...
...its table name and id, use the following approach on ActiveRecord::FixtureSet: table = 'users' # Specify the fixture table name id = 123122 # Specify the ID to look for # Find the fixture...
@model_class= User(id: integer, ...)> # Associated model class ] Replace 'users' with the specific table/fixture name you are targeting. Replace 123122 with the desired ID for the lookup.
If you use the selenium-webdriver gem, it will sneakily phone home once every hour whenever you run a browser based feature spec. You can opt out either locally:
...export SE_AVOID_STATS=true or project based # spec_helper.rb ENV['SE_AVOID_STATS'] = 'true' To test if it works Go offline Remove ~/.cache/selenium/se-metadata.json Run a JS feature spec
...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...
These two addons will change your life: Search as list This will always open search results in the list views instead of the barely usabely faceted search view.
...results by date not relevance Does what it says...
The terraform documentation states the...
...syntax as (grouping mode*. See: Grouping-Results). But this seems not the be the whole truth. Instead the...
...syntax behaves like Go's Ellipsis expression...
...is only available for for expressions. This can be especially useful when creating data structures in loops: users = { users = { "Bob.Bobster" = { name = { given_name = "Bob" family_name = "Bobster" } email = "bob.bobster@foobaringen.com"
SimpleForm is a great approach to simplifying your forms, and it comes with lots of well-defined input types. However, the :grouped_select type seems to be overly complicated for...
Consider this example, from the documentation: form.input :country_id, collection: @continents, as: :grouped_select, group_method: :countries While that looks easy enough at a first glance, look closer. The...
...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...
The linked article suggests an interesting way to speed up tests of Rails + Postgres apps: PostgreSQL allows the creation of “unlogged” tables, which do not record data in the PostgreSQL...
...Write-Ahead Log. This can make the tables faster, but significantly increases the risk of data loss if the database crashes. As a result, this should not be used in...
...an element's attributes in Capybara. A few examples: find('#my_element')['class'] # => "first-class second-class" find('#my_input')['placeholder'] # => "My placeholder value" find('a#example-link')['href...
By pressing Ctrl + Shift + V you can select a recently copied string for pasting...
...breakpoint tier in JavaScript, employ this CSS: :root { --current-breakpoint-tier: xs; @media (min-width: $screen-sm-min) { --current-breakpoint-tier: sm; } @media (min-width: $screen-md-min) { --current-breakpoint...
} @media (min-width: $screen-lg-min) { --current-breakpoint-tier: lg; } @media (min-width: $screen-xl-min) { --current-breakpoint-tier: xl; } @media (min-width: $screen-xxl-min) { --current-breakpoint...
...not on par with your IDE of choice. I have found that it also slows down my IRB in some cases, or that pressing the Backspace key does not always...
...annoying than useful. You may disable multi-line autocomplete by using the --nomultiline commandline switch (for Rails, use bin/rails console -- --nomultiline), or specifying IRB.conf[:USE_MULTILINE] = false in your ~/.irbrc...
Sometimes you will need an input field which wraps content and grows in height as soon as content gets longer than the input fields width. There is no way to...
...get a "normal" string input field to wrap as desired, but there are other ways. Here is one pretty easy solution to get what you want: Step 1
...where elements break the layout's horizontal container width, like navigation buttons of a slider that should be at the left/right of the browser window, or simply by applying a...
...that. Like margin: 0 -10000px plus overflow-x: hidden. There is a much saner approach. Consider the following markup: Hello Let's say .container encloses its contents like so...
...full trace reveals that ActionPack's action_controller/integration.rb is breaking while doing this: cookies = @headers['Set-Cookie'] cookies = cookies.to_s.split("\n") unless cookies.is_a?(Array) cookies.each do |cookie| name, value = cookie.match...
...happened for me. That is how my cookie looked when debugging: (rdb:1) puts headers['Set-Cookie'] remember_token=abcdef123456; path=/; expires=Mon, 31-Dec-2029 23:03:29 GMT...
This StackOverflow question about nested function definitions in Ruby imparts a good understanding of Ruby's def...
Use the click method on the DOM element: let link = document.querySelector('a') link.click()
There are cases when you need to select DOM elements without jQuery, such as: when jQuery is not available when your code is is extremely performance-sensitive
...an entire HTML document (which is hard to represent as a jQuery collection). To select descendants of a vanilla DOM element (i.e. not a jQuery collection), one option is to...
The ancestry gem allows you to easily use tree structures in your Rails application. There is one somewhat unobvious pitfall to it: its way of applying the orphan_strategy which...
...might want to disallow destruction if there are any child nodes present. The restrict strategy does the trick but raises an exception when destroy is called: has_ancestry :orphan_strategy...
Ever seen this error when using Graticule? Numerical argument out of domain - acos Similarly to the to_sql problem for some edge cases, Graticule::Distance::Spherical.distance (and possibly those of...
...Graticule's other distance computation classes) is subject to Float rounding errors. This can cause the above error, when the arc cosine of something slightly more than 1.0 is to...
If you want to know your public key's fingerprint, do this: ssh-keygen -lf ~/.ssh/my.key.pub This may be necessary to authenticate your key on GitHub because of recent events...
...them (to pull etc): ERROR: Hi foobear, it's GitHub. We're doing an SSH key audit. Please visit https://github.com/settings/ssh/audit/... to approve this key so we know it...
You are not using javascript tests The file is served from a public folder (not via controller) Problem description If you deliver files from a public folder it might...
...be that the Content-Disposition header is not set. That's why the following spreewald step might raise an error: Then I should get a download with filename "..." expected: /filename...