Did you use the :select option in a find, and forgot to include foo...

Upgrade the offending gem. If you cannot or don't want to upgrade, lock rake to 0.8.7.

...where every value is an object). Some values are sometimes a primitive value (e.g. "foo") and sometimes an object (new String("foo")) and each form requires different checks

x = true typeof x === 'boolean' // => true Strings Strings can exist as literal ("foo") and as an object (new String("foo")), hence we cannot rely on typeof:

w3.org

...in all somewhat modern browsers, and IE9 or later. Match variants Exact match (CSS2) [foo="bar"] (matches , but not ) Exact match for whitespace-separated values (CSS2) [foo~="bar"] (matches )

...class attribute, this is the same as .bar. Match against beginning of value (CSS3) [foo^="bar"] (matches ) Note that matching a class is not as straight-forward, since the class...

...object that looks and acts like a String, but actually is a ActiveSupport::SafeBuffer: "foo".length # => 3 "foo".class # => String "foo".html_safe.length # => 3 "foo".html_safe.class # => ActiveSupport::SafeBuffer The behavior of...

...value as an argument to a method invocation is easy: expect(object).to receive(:foo).with('arg1', 'arg2') This expectation would be met with this call: object.foo('arg1', 'arg2')

...that the argument is an instance of a certain class expect(object).to receive(:foo).with(instance_of(Person)) Test that the argument responds to certain methods expect(object).to...

...ActiveRecord::Migration def change rename_table :old_table, :new_table add_column :new_table, :foo # ... reversible do |direction| direction.up do update "UPDATE new_table SET foo = something_really_complex"

...direction.down do update "UPDATE new_table SET foo = what_it_was_before" end end end end Note that the "down" path is like running the change block from bottom upwards...

TLDR: Ruby class variables (@@foo) are dangerous in many ways. You should avoid them at all cost. See bottom of this card for alternatives. Class variables are shared between a...

...class variables for other classes. Say you have the following code: module Mod def foo @@foo end end class Klass include Mod end @@foo does not mean Klass::@@foo (qualifier...

...that it may cache images/foo.png for 10 years, and you make a change to foo.png, the browser will only notice the change after 10 years. How Rails solves the caching...

...is to attach a timestamp or content hash to your asset's filenames, e.g. foo.png becomes foo-2179b43e243cf343.png. This way, when the asset changes, its URL changes. You can now safely...

...that only accepts application/json will raise an error: An ActionView::MissingTemplate occurred in pages#foo: Missing template pages/foo, application/foo with {:locale=>[:de], :formats=>[:json], :handlers=>[:erb, :builder, :haml]}

...because Rails tried to find a template like foo.js.erb but all it found was foo.html.haml (which the client doesn't understand). Why does someone request my page with weird formats...

...say you have a gem which has the following module: module SuperClient def self.foo 'Foo' end def bar 'Bar' end end For reasons you need to override foo and bar...

module SuperClientExtension def self.prepended(base) base.singleton_class.send(:prepend, ClassMethods) end module ClassMethods def foo 'New foo' end end def bar 'New bar' end end module SuperClient prepend SuperClientExtension

...text, where you want to squish newlines. (multi-line -> one-line) Ruby 2.3+ def foo bar = <<~TEXT line1 line2 line3 TEXT puts bar.inspect end foo => "line1\nline2\nline3\n"

...Forms that work in older Rubies Older forms don't automatically unindent lines: def foo bar = < "line1\nline2\nline3\n" def foo bar = < " line1\n line2\n line3\n"

...manually, you need to follow this guide. Ruby In Ruby, use CGI.escape: # ✅ good CGI.escape('foo=foo&bar=bar') => "foo%3Dfoo%26bar%3Dbar" Do not ever use URI.encode or its alias...

...URI.escape, which keeps control characters like & or = unescaped: # ❌ bad URI.encode('foo=foo&bar=bar') => "foo=foo&bar=bar" Javascript In Javascript, use encodeURIComponent: // ✅ good encodeURIComponent('foo=foo&bar=bar')

...always strings. Non-string keys are silently cast to strings: let hash = {} hash[1000] = 'foo' hash['1000'] = 'bar' hash[document.body] = 'baz' hash // => { '1000': 'bar', '[object HTMLBodyElement]': 'baz' }

...hash of non-string keys, use Map instead: let map = new Map() map.set(1000, 'foo') map.set('1000', 'bar') map.set(document.body, 'baz') map.get(1000) // => 'foo' map.get('1000') // => 'bar' map.get(document.body) // => 'baz...

...will not throw either. In the following example two handlers are listening to the foo event. The first handler crashes, the second handler still runs: document.addEventListener("foo", function(event) {

...new Error("Event handler crashed") }) document.addEventListener("foo", function(event) { console.log("I will run even though the previous handler crashed") }) let fooEvent = new CustomEvent("foo") document.dispatchEvent(fooEvent) // will not throw

makandra dev

...table includes, inter alia, our declared introduce method. This means that declaring a class Foo internally creates a Foo (RClass) which contains the methods defined using def ; end. Instances of...

...Foo then are RObjects that hold a pointer to Foo (RClass) as class reference (klass) and one to the instance variables with the values for the concrete object (iv_table...

...as_trait do |audience| HELLO = "hello #{audience}" # don't do this end end class Foo include ExampleTrait["world"] end No problem so far: >> Foo::HELLO => "hello world" We then include...

end Bar::HELLO is set to "hello universe": >> Bar::HELLO => "hello universe" But Foo::HELLO has also changed! >> Foo::HELLO => "hello universe" # oh no Solution In the as_trait...

...any! Treat it as what it is: potentially unsafe user input. For example: /pages/edit?foo= --> params == {:foo => ""} /pages/edit?foo --> params == {:foo => nil} /pages/edit?foo[] --> params == {:foo => [nil]} # at least in...

...long delay), '...

...', 'script end'. Talking to asynchronous (or "evented") API print('script start') get('foo', done: function(html) { print(html) }) print('script end') Script outputs 'script start', 'script end', (long...

...translate basic control flows from sync to async style. Return a value Sync function foo() { return 'foo' } Async function foo() { return Promise.resolve('foo') } Throw an exception Sync function foo() {

...actually plan to display or change it. Understand that an expression like User.where(email: 'foo@bar.com') does not make an SQL query. It simply returns a scope object for further chaining...

...Queries in Rails Tips Preventing scopes from loading A scope like User.where(email: 'foo@bar.com') does not make an SQL query. It simply returns a scope object for further chaining with...

relishapp.com

...equality with ==. For that, you might want to use eq instead: # does NOT work foo.should == 42, 'Not a valid answer' # Works fine foo.should eq(42), 'Not a valid answer'

...want to wrap your expectation and compare against a boolean, maybe like this: expect { foo > 23 }.to be_true, 'Not a valid answer' If things get too tricky, you could...

...prevents referencing closures, scopes, etc. from being garbage-collected. This code leaks memory: @app.directive 'foo', -> link: (scope, element, attributes) -> $(document).on 'click', -> # code here To prevent leaks you must manually...

...elements that are not your own descendants. This code does not leak memory: @app.directive 'foo', -> link: (scope, element, attributes) -> listener = -> # code here $(document).on 'click', listener scope.$on '$destroy', -> $(document...

makandra dev

class SomeController < ActionController::Base def old_location redirect_to(new_location_url(params.permit(:foo))) end end This will: It will redirect with a 302 status code

...ActionController::UnfilteredParameters if there is any other query param than foo, e.g. https://www.example.com/old_location?another_param=1. This is because url_for will call to_h on ActionController::Parameters, which will raise...

...the scope parameter was blank? and aborted the method execution in this case. def foo(scope) return if scope.blank? # Use scope, e.g. scope.find(...) end We then called this method with...

...an all scope: foo(Media::Document::Base.all). Be careful with this. all returns a scope (ActiveRecord::Relation) which looks and is harmless at first because nothing is loaded into memory...