...is edited by WSYIWYG-Editor but want some length checking nevertheless, you need to strip all tags and then the special characters: def hard_sanitize(text) ActionController::Base.helpers.strip_tags(text...
...gsub(/[^[:word:]]+/, " ") end :001 > hard_sanitize("This is beautiful markup ") => "This is beautiful markup" If you allready have nokogiri on board, you can use that as well, though it has...
...when you work for clients from Europe or the US, there are two dominantish standards you should know about. Each of these has subtle differences. ISO 8601 This is adhered...
...to by most European countries. Weeks start on Monday and end on Sunday. To get the number of the weekday in Ruby as defined by ISO 8601, use Date#cwday...
Rails 5.2+ supports "verbose query logs" where it shows the source of a query in the application log. Normally, it looks like this: User Load (0.5ms) SELECT "users".* FROM...
...app/controllers/users_controller.rb:42:in `load_users' However, you may encounter ActiveRecord's LogSubscriber as the source for all/most queries which is not helpful at all: User Load (0.5ms) SELECT "users...
With ES2021 you now can use str.replaceAll(), Promise.any(), logical assignment operators, numeric separators and WeakRef on all major browsers except IE11. replaceAll JavaScript's replace(searchValue, replaceValueOrFn) by...
...default replaces only the first match of a given String or RegExp. When supplying a RegExp as the searchValue argument, you can specify the g ("global") modifier, but you have...
Delegating methods to other objects is often helpful but the syntax of both def_delegators and def_delegator is a complete mess that makes your code hard to read.
...ActiveRecord::Base belongs_to :topic def_delegators :topic, :title, :category end Here, we can say Post.new.title and actually read title from the Post's Topic object. Because of what we...
The SQL code generated by Graticule's spherical distance computation is insufficient and can lead to NULL distances in edge cases. The reason for this is that MySQL is performing...
...several sine and cosine computations which can result in slight rounding errors -- which is usually okay. Rarely, though, for the exact center of the given circle, it is then asked...
Given those modules: module A def foo; end def bar; end end module B end When you want to call...
...MySQL and you know the "error" is okay (e.g. you've executed the same statement at the same time on 2 masters which sync each other), you can skip this...
...error and continue with the replication without having to set up the slave from the ground up. stop slave; set global sql_slave_skip_counter = 1; start slave;
...so I hope it will be fixed with a future release. The following test succeeds: context 'factories' do let(:test_case) { FactoryBot.create(:test_case) } it 'are valid' do expect(test...
...byebug) FactoryBot.create(:test_case) *** NameError Exception: uninitialized constant # ::TargetLimitation Did you mean? TargetsTestScenario It seems like Byebug does not work well with zeitwerk. There is already a patch in Ruby...
...written in pure Ruby and integrates with Rails applications. It provides features as automatic sizing of dots and lines (the more values, the thinner the graph's elements), custom or...
...predefined themes, different styles (bar, line, dot and many more) and multiple graphs in one chart. Installation In your Gemfile: gem 'rmagick', :require => false gem 'gruff' Then run bundle install...
...entering only http://example.com/). If you want to make a request to that site's web server without actually talking to www.example.com (e.g. because this is a load balancer...
...s address but you want to access one specific machine), you cannot just request machine1.example.com or localhost as the above vhost will redirect your request. When talking HTTP 1.1, your...
How to ignore new files Globally Add the path(s) to your file(s) which you would like to ignore...
...On purpose? Right... In Gnome Make it an additional ESC key by going to System -> Preference -> Keyboard -> Layouts -> Options -> CapsLock key behavior and select "Make CapsLock an additional ESC".
...to using dconf. dconf write /org/gnome/desktop/input-sources/xkb-options "['caps:escape']" Or, open Tweak advanced GNOME 3 settings and follow Keyboard & Mouse -> Additional Layout Options to chose the same option as described above...
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...
...crawlers to not access that path. robots.txt is not a guarantee for exclusion from search engine results. A "disallowed" URL might be known from an external link, and can still...
...links. Popular pagination libraries like will_paginate or Kaminari do this for us by simply issuing an extra query, like this: SELECT post.* FROM posts LIMIT 20 OFFSET 100;
...of the time. But rarely, you might have very complicated WHERE conditions or a subquery that takes time to run. In these cases, doing two queries is slower than it...
can’t find executable rails for rails-3.2.3 (Gem::Exception) ... one of several...
...things might be wrong. You're using RVM It's possible that you have a system-wide gem executable (like rails) that requires a gem that is not available in...
A print stylesheet is easy to create. Choose a font suited for paper, hide some elements, done. Unfortunately print stylesheets often break as the application is developed further, because they...
...are quickly forgotten and nobody bothers to check if their change breaks the print stylesheet. This card describes how to write a simple Cucumber feature that tests some aspects of...
Capistrano 2 brings the shell command which allows you to run commands on your deployment targets. There is also invoke to run a command directly from your terminal.
...allow running Capistrano tasks or shell commands, and scope to individual machines or machine roles. Unfortunately Capistrano 3 does not include these commands any more. cap shell Basics
On your local system that only hosts non-critical development data and only you have access to, you can store MySQL's root password in your home directory so you...
...out of the question if there's any confidential data in your databases. Assuming diligent screen-locking, an encrypted hard disk and correct permissions set on your credential file, it...
A comprehensive introduction to sending HTML emails. Intro: HTML email: Two words that, when combined, brings tears to a developer’s eyes. If you’re a web developer, it’s...
...in your career, whether you like it or not. Coding HTML email is old school. Think back to 1999, when we called ourselves “webmasters” and used Frontpage, WYSIWYG editors and...
Spreewald's patiently repeats the given block again and again until it either passes or times out. Be careful to give patiently a block that can actually be repeated. E.g...
...the field variable that was defined outside of the block (it's the variable set from the Given block's arguments). Because of this, during the first repetition the value...
...Ever wanted to give an element "the container's width minus 20px on each side"? Here you go: .foo { width: calc(100% - (20px * 2)); } When using Sass, you need to...
...interpolate Sass expressions: $margin: 20px * 2 .foo width: calc(100% - #{$margin}) Supported by all modern browsers and IE9...
...run rake and your code is causing an exception which is not the one shown in your terminal. Rails tries to catch this exception and clean up constants but -- while...
...it's still booting up -- fails on this which causes another exception: rake aborted! cannot remove Object::ClassMethods Running rake with the --trace parameter will give you no love; the...
...message like this, rubygems.org might have issues with their ipv6 connectivity: $ bundle install Fetching source index from https://rubygems.org/ Retrying fetcher due to error (2/4): Bundler::HTTPError Could not fetch...
...specs from https://rubygems.org/ due to underlying error <timed out (https://rubygems.org/specs.4.8.gz)> The (a little bit dirty) possible solution If that's actually the case, then you can try...