...test you can also use a handful of rake tasks to prepare the database structure directly. They can produce different results, though. In a nutshell, to ensure your test database...

...gains the correct structure: Don't use rake db:test:prepare carelessly or use rake db:test:clone_structure ← preferred :) or use rake db:migrate RAILS_ENV=test and don...

...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...

...AWS elasticache is memcached) telnet foohost23.cs2631.0001.euw1.cache.amazonaws.com 11211 Once you're connected, find out which 'slabs' exist within the cache: stats items STAT items:1:number 3550 STAT items:1:age...

...STAT items:1:evicted 0 STAT items:1:evicted_nonzero 0 STAT items:1:evicted_time 0 STAT items:1:outofmemory 0 STAT items:1:tailrepairs 0

Situation: You want to write a spec for a function inside an Angular service. This function at some point makes an API request and acts upon response. Notably, your Angular...

...uiRouter, although it is not used nor actually required for this test. Working test setup # Capitalized expressions are intended to be replaced with YOUR values describe 'SERVICE', -> beforeEach -> module 'MODULE...

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

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?

makandra dev
semaphoreci.com

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...

When your JavaScript bundle is so massive that you cannot load it all up front, I would recommend to load...

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.

makandra dev
innig.net

...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...

makandra dev
poinz.herokuapp.com

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...

...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

makandra dev

...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...

makandra dev

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...

...filled out at the same time, there is no built-in validation. I've seen different solutions in the wild, each with different downsides: Private method referenced via validate: works...

...name, :nickname, xor_presence: true end Validator Here is the validator class; put it somewhere in your project. class XorPresenceValidator < ActiveModel::Validator def initialize(options) @attributes = Array.wrap(options[:attributes]).freeze...

...check checkboxes. But there's one problem, if you want to test a custom styled checkbox, which hides its -Tag: The methods cannot (un)check checkboxes without an visible .

...error message will be something like: Unable to find visible checkbox "Some label" that is not disabled Solution 1 Use the keyword argument allow_label_click: true within the method...

RubyMine offers you to exclude directories from search, meaning faster search results and less "noise" in the list of result. Right-click a folder in your project tree and click...

...and other directories that you don't need to access during development and whose search results are irrelevant. They won't be deleted but simply ignored when searching across a...

Sometimes, the rails dev server doesn't terminate properly. This can for example happen when the dev server runs in a RubyMine terminal. When this happens, the old dev server...

...blocks port 3000, so when you try to start a new server, you get the error: Address already in use - bind(2) for "127.0.0.1" port 3000 (Errno::EADDRINUSE)

dev.to

...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...

postgresql.org

...is pretty useful, but manipulating values of arrays can be awkward because of its syntax. Consider the following users table which each example below will start from: name topics

Bob {llamas} (PostgreSQL uses curly braces to represent arrays, true story.) Adding values Use the array_cat function, or the || operator. These calls will add the values "cats...

A datetime in MySQL does not have a zone. It just stores the literal string "2010-05-01 12:00:00". That means that Rails must make...

...mode Rails assumes that your application lives in the same time zone as your server's local zone settings. In this mode ActiveRecord will not try to convert times coming...

Sometimes it is useful to define a named scope by implementing a static method with the scope's name on the scoped class. For instance, when a method should decide...

...which existing scope should be the next link in the scope chain. Take this class for example: class Meal < ActiveRecord::Base named_scope :for_date, lambda { |date| :conditions => { :date => date...

makandra dev

...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...