IRB 1.2 (shipped with Ruby 2.7, but works on 2.5+) brings pretty syntax highlighting and multiline cursor navigation. However, pasting...

Rails' url_for is useful for generating routes from a Hash, but can lead to an open redirect vulnerability.

...shared_examples_for can have parameters. You can simply hand over arguments from it_behaves_like: shared_examples_for 'string equaling another string' do |expected_string| it 'is equal to...

...subject).to eq(expected_string) end end describe 'some string' do subject { 'foo' } it_behaves_like 'string equaling another string', 'foo' end RSpec 1 Use it_should_act_like from...

...between added? and of_kind? While added? might feel more natural to use, it behaves differently than of_kind? because it also compares options from the validation error. of_kind...

While it might be tempting to set it per project (other devs might benefit from it), you need to do it each time for every project "pollute" a project...

When two classes implement the same behavior (methods, callbacks, etc.), you should extract that behavior into a trait or module. This card describes how to test that extracted behavior without...

...repeating yourself. Note that the examples below use Modularity traits to extract shared behavior. This is simply because we like to do it that way at makandra. The same techniques...

makandra dev

...changes you make to the database will be rolled back on exit. Warning Changes beyond the database (deleting files, sending emails, etc) cannot be rolled back...

When ending a Selenium test Capybara resets the browser state by closing the tab, clearing cookies, localStorage, etc.

...Middleman brings Haml, Sass, helpers etc. However, it can be configured to do even better. This card is a list of improvement hints for a Rails developer. Gemfile

...helpers in a helpers {...

...} block. However, this does not scale very well. You're best off creating a /helpers directory and putting helper files there just like you know it...

class Post < ActiveRecord::Base has_one :attachment end # attachment.rb class Attachment < ActiveRecord::Base belongs_to :post validates :title, presence: true end Issue When creating a post with an invalid...

workingdraft.de

The robots.txt file and HTML tag can be used to control the behavior of search engine crawlers. Both have different effects. robots.txt Marking a URL path as "disallowed" in robots.txt...

Since I use this a lot in my daily work and there were no scripts working properly for me, I...

To apply transparency to an element, you can use opacity in CSS. However, sometimes you don't want to make...

...index: true option. Use it only inside create_table or for add_reference (= add_belongs_to) statements, and use add_index for other cases. Never use index: true but only...

Besides Plotting graphs in Ruby with Gruff, which comes handy for many uses cases, you sometimes might need configuration for more advanced plots, e.g. for academic concerns. Then using Gnuplot...

...where each array holds the data for x-, y- or z-axis. The major benefit of numo-gnuplot is that it supports advanced numpy like array operations, like multi array...

SimpleForm is a great approach to simplifying your forms, and it comes with lots of well-defined input types. However...

If you ever need to restore exact records from one database to another, Marshal might come in handy. Marshal.dump is...

TL;DR There are three dimensions you can control when scoping routes: path helpers, URL segments, and controller/view module.

...all Unpoly updates work using AJAX requests, you won't get the more detailled better_errors page with the interactive REPL. Below is an event listener that automatically repeats the...

...full CSS and JavaScript. The code assumes you are using Ruby on Rails with better_errors, which is the default error view that modern Rails versions employ. If you are...

web.archive.org

There is a common view that extracting text from a PDF document should not be too difficult. After all, the...

Capybara provides execute_script and evaluate_script to execute JavaScript code in a Selenium-controlled browser. This however is not...

makandra dev
relishapp.com

RSpec 3 has verifying doubles. This breed of mock objects check that any methods being stubbed are present on an...

...follow redirects to get the desired response. This is supported but not the default behavior. You can do so by using the .follow method. This follows redirects for the following...

When your Rails application offers downloading a bunch of files as ZIP archive, you basically have two options: