...approaches in Rails, how you can assign such an association via HTML forms. Option 1: Array column One way to solve the problem is using a database column with an...
...We need to take care of not assigning nil as value of posts Option 1: Using with_defaults! in the controller + include_hidden: false in the form (used in the...
...used for the same effect. Relation#to_sql # Rails 2 scope Post.scoped(:conditions => { :id => [1, 2] }).to_sql # => "SELECT `posts`.* FROM `posts` WHERE `posts.id` IN (1, 2)" ^ # Rails 3 relation...
...Post.where(:id => [1, 2]).to_sql # => "SELECT `posts`.* FROM `posts` WHERE `posts.id` IN (1, 2)" Implementation note: Rails 3+ implements #to_sql. Relation#to_id_query Site.joins(:user).where(:users...
...A-Za-z0-9]+> is easier to write but matches invalid tags such as <1>. Use \b[1-9][0-9]{3}\b to match a number between 1000 and...
...Use \b[1-9][0-9]{2,4}\b matches a number between 100 and 99999. Modes: Greedy, Lazy and Possessive Example string: This test is a first test string...
...the constructor. returnValue & returnValues it('shuffles the array', () => { spyOn(Random, 'shuffle').and.returnValue([3, 2, 1]) array = [1, 2, 3] testedClass = new testedClass(array) expect(Random.shuffle).toHaveBeenCalled() expect(testedClass.array).toEqual...
}) If you have several new classes created in one test you could also use returnValues for any call of the method Random.shuffle. callFake If you are testing the class...
...can list them like this: $ git stash list stash@{0}: WIP on feature/foo stash@{1}: WIP on feature/bar stash@{2}: WIP on fix/baz All those stashed changes have their own...
...reference (like branch names) that you can look at, like stash@{0}, stash@{1}, etc. Above, we looked at stash@{0} which is the default for stash actions.
# for which the block evaluates to true, # the second containing the rest. (1..6).partition { |v| n.even? } #=> [[2, 4, 6], [1, 3, 5]] Works well with destructuring assignment...
even, odd = (1..6).partition { |n| n.even? } even #=> [2, 4, 6]
The sprintf method has a reference by name format option: sprintf("% d : % f", { :foo => 1, :bar => 2 }) # => 1 : 2.000000 sprintf("%{foo}f", { :foo => 1 }) # => "1f" The format identifier % stands for...
...different data types to be formatted, such as %f for floats: sprintf('%f', 1) # => 1.000000 Example: This is quite useful to replace long strings such as API endpoints which might...
...database's EXPLAIN style. For example, it looks like this on MySQL: User.where(id: 1).includes(:articles).explain EXPLAIN for: SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 +----+-------------+-------+-------+---------------+
...type | table | type | possible_keys | +----+-------------+-------+-------+---------------+ | 1 | SIMPLE | users | const | PRIMARY | +----+-------------+-------+-------+---------------+ +---------+---------+-------+------+-------+ | key | key_len | ref | rows | Extra | +---------+---------+-------+------+-------+ | PRIMARY | 4 | const | 1 | | +---------+---------+-------+------+-------+ 1 row in set (0.00 sec) EXPLAIN for: SELECT `articles...
2 application servers 6 Rails worker processes in each application server 1 background job server with Sidekiq (will spawn 10 threads by default) When your code does...
...you may use the following number of connections: (2 app servers * 6 app workers) + (1 job server * 10 sidekiq workers) = 12 + 10 = 22 connections When your code does use ActiveRecord...
...has_many :users end Here activity 42 has four users: activity = Activity.find(42) activity.users.ids # => [1, 2, 3, 4] Let's say we want to do the same on all activities...
...By reloading the object, its full list of associated users is restored: activity.reload.users.ids # => [1, 2, 3, 4] Or you can reset the association cache: activity.users.reset # newer Rails activity.users(true) # old...
Unfiltered: `User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."token" = $1 LIMIT $2 [["token", "secret-token"], ["LIMIT", 1]]` After the filter is applied:
...ms) SELECT "users".* FROM "users" WHERE "users"."token" = $1 LIMIT $2 [["token", "[FILTERED]"], ["LIMIT", 1]]` Unfortunately, this mechanism is not always applied, because of code dependencies. Some are written by...
attribute attr end validates *REQUIRED_ATTRIBUTES, presence: true validates *ALL_ATTRIBUTES, length: { maximum: 1000 } # From this you already get methods like `#valid?` and `#==`. # (optional) Here is the perfect place...
...Address instance: # without :mapping Rails uses keyword arguments Address.new(street_and_number: 'Foo St. 1', zip_code: '12345', city: 'Bar Town') # with a :mapping (even if that is just the...
The git doc states on the difference of these two commands: git-restore[1] is about restoring files in the working tree from either the index or another commit. This...
...also be used to restore files in the index from another commit. git-reset[1] is about updating your branch, moving the tip in order to add or remove commits...
...This task list is divided by the Gate keeping process in the following steps: 1. Starting a new feature 2. Working on the issue 3. Finishing a feature
...design and the points from Building web applications: Beyond the happy path The template: 1 Starting a new feature Set the issue to "In Progress" in Linear Pull the most...
...a new frame is rendered 60 times a second. Thus, a single frame is 1000ms / 60 = 16.6...ms long. Once a frame renders longer than 16ms, the page will begin...
...s well searchable when you just have a question about some function. Performance issue 1: Slow JavaScript If an event occurs and JavaScript has to run, the browser have to...
...using Geordi, disable automatic updating of chromedriver in ~/.config/geordi/global.yml: auto_update_chromedriver: false Option 1: Use Geordi The geordi gem can upgrade to the correct version of chromedriver: geordi chromedriver...
...z "$VERSION" ]; then echo "Failed to read current version from $VERSION_URL. Aborting." exit 1 else echo "Current version is $VERSION" fi # Abort script if any of the next commands...
...within the diff. Colors The value for color configuration variables is a list of 1-2 colors and 0-1 attributes, separated by spaces. Colors: normal, black, red, green, yellow...
...a SHA1 revision. Your editor will open with a file like pick fda59df commit 1 pick x536897 commit 2 pick c01a668 commit 3 Each line represents a commit (in chronological...
...these commits into a single one, change the file to this: pick fda59df commit 1 squash x536897 commit 2 squash c01a668 commit 3 This means, you take the first commit...
end def db_number # Returns a number between 2 and n. # Redis db#1 is used for development. db_number = 1 if rails_env == 'test' normalized_test_number = [ENV...
...TEST_ENV_NUMBER'].to_i, 1].max db_number += normalized_test_number end db_number end def port case rails_env when 'staging' # when 'production' # else 6379 # default Redis port...
...is to encode the string using JSON, and then escaping all code points above 127 using unicode escape sequences: escapeHighASCII('{"foo":"xäy"}') // => '{"foo":"x\\u00e4y"}' Escaping high ASCII in JavaScript...
...function escapeHighASCII(string) { let unicodeEscape = (char) => "\\u" + char.charCodeAt(0).toString(16).padStart(4, '0') return string.replace(/[^\x00-\x7F]/g, unicodeEscape) } Escaping high ASCII in Ruby def escape_high_ascii(string...
...enabled for node. Installing nvm DigitalOcean has a HOWTO for installing nvm on Ubuntu (16.04, 18.04, 20.04) that I recommend. During the installation of node via nvm, a compatible version...
...to be done separatly for each node version on your system, though. Install yarn 1 system-wide via apt The yarn package depends on the nodejs debian package, but with...
...shutdown the Elasticsearch cluster, as soon as everything works as expected. flowchart TB subgraph "1" A0[App]-- Search -->ES0[Elasticsearch] A0[App]-- Update -->ES0[Elasticsearch] OS0[OpenSearch] end
...please refer to the breaking changes linked below. On request we may provide OpenSearch 1.x corresponding to Elasticsearch 7.x. How do you update your application? This depends on...
...you might want to enable logging for the chromedriver itself. Here is how. Option 1: Use Selenium::WebDriver::Service In your test setup, you may already have something like Capybara...
...can also start chromedriver yourself in a terminal on a custom port: chromedriver --port=12345 --verbose --log-path=/tmp/chromedriver.log Then configure Selenium to connect to that port. Like in option...
An example would be an AngularJS application where the following HTML actually works. [1] Hello Capybara will fail to find that link, even though looking it up via the...
...and click_link work, simply add href="#" to your element: Hello >> find_link("Hello") => # [1] Note that while it does work in your application (links are usually styled correctly, and...