Sometimes I ran across a GitHub merge request of a gem where it was not completely obvious in which version the change was released. This might be the case for...
Git can help you to find the next git tag that was set in the branch. This usually has the name of the version in it (as the...
tl;dr: Do not use merge! for session hashes. Use update instead. Outline Let's assume you're modifying the Rails session. For simplicity, let's also assume your session...
...is empty when you start (same effect when there is data): # In our example, we're in a Rack middleware request = Rack::Request.new(env) request.session.merge! :hello => 'Universe' request.session => {} Wat?
Capistrano 3 is a major rework of the framework and requires several adjustments to your deploy configuration files. The biggest change is that they moved away from their custom DSL...
...release_roles|...) :some_role do Resources Very helpful, leads you 90% of the upgrade: https://semaphoreci.com/blog/2013/11/26/capistrano-3-upgrade-guide.html Official documentation Many examples of SSHKit...
If you're on Ruby 2.3+ there's a <<~ operator to automatically unindent HEREDOCs: str = <<~MESSAGE Hello Universe! This is me. Bye! MESSAGE If you have an older Ruby, you...
...can use the String#strip_heredoc method from ActiveSupport. See Summarizing heredoc in ruby and rails for an example. Technically, it looks for the least indented line in the whole...
Web forms can be made much more usable with a few HTML attributes. Short summary: type: Tells browsers about the input data type. Mobile browsers will select a virtual keyboard...
...based on this value. Some browsers will add simple validation, e.g. for type email. inputmode: Direct hint about the virtual keyboard to use. Inferred from type, but can be very...
...you want to clean up this code with the modularity gem, you might try something like this: class Foo does 'bar' end module BarTrait as_trait do class Bar
...you would have to change all references accordingly, which is quite unpleasant. You can solve it like that: module BarTrait as_trait do class self::Bar end end end
...lambdas in Ruby work, check out the code at the attached link. Here the summary: ^ ---------------------------- Section 6: Summary ---------------------------- So, what's the final verdict on those 7 closure-like entities...
...method Y closure yes The things within each of these groups are all semantically identical -- that is, they're different syntaxes for the same thing: 1. block (called with yield...
It is possible to manipulate the forwarded ports of an established interactive SSH session. This is done by opening the command line with the escape character ~C. This will open...
...a ssh> prompt. If it doesn't, make sure it's the first character in a line, i.e. press enter first. You have following commands at your disposal
...Ruby parser module of Ruby-GetText comes across a file in one of its search directories (e.g. lib/scripts/) and finds out that you are defining ActiveRecord classes inside it, it...
...the whole file. Here is how to avoid that. What's happening? Let's say you have the following script which is only run once, manually, via script/runner: # lib/scripts/doomsday.rb
...file download links in an end-to-end test can be painful, especially with Selenium. The attached download_helpers.rb provides a download_link method for your Capybara tests. It returns a...
details[:disposition] # => 'attachment' or 'inline' details[:filename] # => 'report.txt' details[:text] # => file content as string details[:content_type] # => 'text/plain' Features Compared to other approaches this helper has many useful features...
...flaky tests. You should always try to fix those instead of rerunning them regularly. Setup Configure RSpec to persist the result of your test runs to a file. This is...
...necessary to be able to rerun examples. Add this to your spec/spec_helper.rb : config.example_status_persistence_file_path = 'spec/examples.txt' Rerun all failed examples using --only-failures bundle exec rspec --only-failures...
...use Solr by calling Article.search { fulltext(title) paginate(:per_page => limit) } Now look at http://sunspot.github.com/docs/ to learn about all the possibilities of Sunspot. Overwrite Sunspots' search method
...your SysOp team that you'll need Solr on staging and production, on Ubuntu the solr-common will provide what you need. First of all you should provide Solr with...
...lot less than you think. "private" does not apply to class methods defined on self This does not make anything private: class Foo private def self.foo 'foo' end end
...need to use private_class_method instead: class Foo def self.foo 'foo' end private_class_method :foo end "private" does not apply to define_method This does not make anything...
...to accept nested attributes for a record that is not an association, e.g.: class Site < ActiveRecord::Base def home_page @home_page ||= Page.find_by_name('home') end does 'accept_nested...
...attributes_for_member', :home_page end It has some limitations: Only works for singular member references ("belongs to"), not for a collection of references ("has many") No support for deletion...
Remember How to skip Sprockets asset compile during Capistrano deployment and Automatically skipping asset compilation when assets have not changed? Turns out there is an even better way to speed...
...up Capistrano deployments with asset compilation – and it's even simpler. Adding the asset cache directory to symlinked directories Popular asset managers for Rails are Sprockets and Webpacker. Both keep...
...exactly(building, other_building) expect(unit.assignable_buildings).not_to include(unauthorized_building, nil) end ... See RSpec: Where to put custom matchers and other support code
When your JavaScript bundle is so massive that you cannot load it all up front, I would recommend to load...
If you are using scrum in a project you might be familiar with planning poker, a playful way to agree on story estimates. PoinZ is an online planning poker app...
You can use three different versions of the regular expression syntax in grep: basic: -G extended: -E(POSIX) perl: -P (PCRE) Difference between basic and extended: In basic regular expressions...
...the meta-characters '?', '+', '{', '|', '(', and ')' loose their special meaning; instead use the backslashed versions '?', '+', '{', '|', '(', and ')'. Difference between extended (POSIX) and perl (PCRE): E.g. \d is not supported in POSIX.
...you can install the official Java JRE: sudo apt-get update sudo apt-get install sun-java6-jre You can now check your default JVM with java -version. It should...
...versions below 10.10. If it does, please update this note. sudo add-apt-repository ppa:sun-java-community-team/sun-java6 You probably want to get rid of OpenJDK (which is...
...alias such as this to your ~/.bashrc: alias recent-branch="git for-each-ref --sort=-committerdate --format='%(refname:short)' refs/heads/ | fzf | sed 's/\* //g' | xargs -I '{}' git checkout {}"
Now whenever you want to switch back and forth between your most recent branches, type recent-branch, select one and press enter...
If you have an html_safe string, you won't be able to call gsub with a block and match reference variables like $1. They will be nil inside the...
...with rails_xss) as well as Rails 3 applications. Here is a fix to SafeBuffer#gsub. Note that it will only fix the $1 behavior, not give you a safe...
The need for clearfix hacks has been greatly reduced since we could layout with Flexbox or CSS Grid. However, when you do need a clearfix, there's no reason to...
...hack anymore. You can just give the clearing container display: flow-root. This is supported by all browsers except IE11...
...ago and don't remember which one it is? You can go to chrome://settings/appearance (on Chrome 61+) to see the theme's name, and click a link to open...
...it in the Chrome Web Store. If you are on an older version, or if the above no longer works, you have to check Chrome's Preferences file. Linux /home/YOUR_USER_NAME/.config/chromium/Default/Preferences...