Haml 3.1.2 displays single quotes in FormBuilder#text_ field html escaped. You may see something like that: David's Chapter Looking at the page's HTML, your field's...

...detailed error message, you can do a Hash#decent_fetch (with the attached code). some_hash.fetch('missing_key') # => KeyError: key not found: "missing_key" some_hash.decent_fetch('missing_key') # => KeyError: Key "missing...

...found in {"id"=>"96814974590_10152840169159591", "created_time"=>"2014-11-18T20:30:41+0000", "story"=>"Audi Deutschland commented on a photo."} You could put this code in an initializer:

...can do it like this: def classes_defining_method(method_name) method_name = method_name.to_sym ObjectSpace.each_object(Module).select do |mod| instance_methods = mod.instance_methods.map(&:to_sym) # strings in old Rubies...

...symbols in new Rubies (instance_methods & [method_name]).any? && mod.instance_method(method_name).owner == mod end end So, when we want to know all classes that define a to_s...

...to an open redirect vulnerability. Your application's generated route methods with a _url suffix are also affected because they use url_for unter the hood. The problem

...use links with your application's hostname, cause a redirect to evil.tld and present a sign-in form which looks like yours. Users will enter their login credentials and submit...

askubuntu.com

Adobe no longer supports their PDF reader on Linux and the official page does not offer it for download. \ However, some files may not display properly on Ubuntu's default...

...PDF reader Evince or PDF forms may not work as expected. Hence, you may still need to use it. Here is how to install the Adobe Reader (acroread) if you...

makandra dev

To change RAM size, VDISK size or VCPU count of an openstack instance you have to use nova resize. You can't change for e.g. just the RAM size with...

...a parameter, you have to assign a new/other flavor. If there is no suitable flavor for the new properties of the VM, create a new one. nova resize [--poll]

When you repeat a subpattern with a *, + or {...} operator, you may choose between greedy, lazy and possessive modes. Switching modes may affect the result and performance of your regular expressions...

...In the worst case, an ill-suited mode may make your regular expression so slow that it can DoS your application (Examples are the ActiveRecord's PostgreSQL CVE...

...more complicates it is easier to understand and to process. Note: In case a string does not match the pattern, .match will return nil. With Ruby 2.4 the result of...

...transformed to a Hash with named_captures. This allows you to use methods like slice or fetch on the result. Example with a multiple assignment PRODUCT_PATTERN = /\A(.+) S\/N...

TypeScript basically uses structural typing, which is conceptually quite similar to duck typing, but with static compile-time type checking. We'll explore what this means in practice.

...a superset of JavaScript, meaning TypeScript compiles down to native JavaScript syntax and checks type consistency only at compile time. Idea of Structural Typing TypeScript only wants to know whether...

...but does not have to be. It's actually very easy when done right. Summary (tl;dr) Here's the short version: Define a table_name_prefix method in the...

...not define any table_name_prefix in ActiveRecord classes inside of it. If this sounds familiar, we have a card about using it already. This card explains why you want...

Let's say you need to revert a migration that happened a while back. You'd create a new migration that removes what was added back then in the up...

...do that. Especially when the up/down paths already contained some logic (that executed update statements on the created column, for example), copying does not feel right. Someone already added the...

...following places and uses the first implementation it finds: Methods from the object's singleton class (an unnamed class that only exists for that object) Methods from prepended modules (Ruby...

...from the object's class Methods from included modules Methods from the class hierarchy (superclass and its ancestors) Example Let's say we have the following class hierarchy: class Superclass...

Rails has configurable time zones, while Ruby is always in the server's time zone Thus, using Ruby's time API will give you wrong results for...

...zones, because their existence is a fact. You can, however, tell Rails the only single time zone you'll need is the server's. config.time_zone = "Berlin" # Local time zone...

makandra dev
getmdl.io

CSS (+ some Javascript) framework, implementing Google's material design for static web pages. Can be used for plain websites without requiring a full blown Javascript framework, unlike the (also excellent...

...elements, or Angular material. Prelimiary impression: I would recommend against using it at this stage, for a couple of reasons: It is much less complete than you might expect from...

kernel.org

Git allows you to do a binary search across commits to hunt down the commit that introduced a bug. Given you are currently on your branch's HEAD that is...

...not working as expected, an example workflow could be: git bisect start # Start bisecting git bisect bad # Tag the revision you are currently on (HEAD) as bad. You could also...

...binary, do not install Ubuntu's node package. Instead, you need to create a symlink that points to the binary one of the nodejs package: sudo ln -s /usr/bin/nodejs /usr/bin/node...

...You probably already installed NodeJS. In case you did not: sudo apt-get install nodejs If you already installed the node Ubuntu package, bower will just do nothing (i.e. not...

Note: This applies to plain Ruby scripts, Rails does not have this issue. When you work with Ruby strings, those strings will get some default encoding, depending on how they...

...are created. Most strings get the encoding Encoding.default_internal or UTF-8, if no encoding is set. This is the default and just fine. However, some strings will instead get...

The most common use case for Ruby's #collect is to call a method on each list element and collect...

github.com

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

...be a quick fix for an existing app. It also ensures that future uploaders get safe-ish defaults when the developer forgets to define an allowlist for concrete uploaders (see...

...you can also go with this more relaxed CSP: Content-Security-Policy: default-src 'self'; script-src 'none'; object-src 'none' While this does not fix users uploading executables etc...

...to be defined ahead of your before block and can be different for individual sections. It works just like that: describe User do describe '#locked?' do before :each do subject.should...

...receive(:current_plan).and_return plan end context 'when expiring today' do let(:plan) { stub(:expiry => Date.today) } it 'should be false' do subject.should_not be_locked end end context 'when...

...full-app localization before and assign an hour estimate to each of these points. Static text Static strings and template text in app must be translated: Screens, mailer templates, PDF...

...templates, helpers, sometimes models. Use the native Rails I18n API. Avoid Gettext if possible. Native I18n has good integration with Rails (you already have it!), but you need to come...

The Node Version Manager allows installing multiple NodeJS versions and switching between them. By default, it does not automatically switch versions when entering a directory that holds a .nvmrc file...

...COMMAND feature. So here is my take on it. Note that it is much shorter, it probably does a few less smart things, but has been working great for me...

Use Socket.gethostname. So for a machine whose hostname is "happycat", it will look like this: >> Socket.gethostname => "happycat" That should work right away for your Rails application. For plain Ruby, you...

...first need to do: require 'socket' If you don't want to use Socket for some reason, you can still just use the hostname command, at least on non-Windows...