...constants, constantize and safe_constantize. Neither is safe for untrusted user input. Before you call either method you must validate the input string against an allowlist. The only difference between...

prettier calls itself an opinionated code formatter. I recommend using it for your JavaScript and TypeScript code. prettier only concerns itself with the formatting of your JavaScript (and also some...

...routes, so we can write it as follows. class RackLoggerWithSilencedActiveStorageRoutes < Rails::Rack::Logger def call(env) if env['PATH_INFO']&.start_with?("#{Rails.configuration.active_storage.routes_prefix}/") Rails.logger.silence do super end else

...element or set scrollTop on both and . Finding the scrolling element Your JavaScript can call document.scrollingElement to retrieve the scrollable element for the main viewport. On Chrome, Firefox and modern...

thegnar.com

...you to use Capybara Finders methods (e.g. #find) on the doc element and then call matchers on that element: link_element = doc.find('a') expect(link_element).to have_selector('.nav...

...by default, such that rendered is converted once one of Capybara's matchers is called on it, it's default type is still a String. (As noted in the Capybara...

...updated_at_of_expensive_scope') fresh_when last_modified: updated_at The example above calls fresh_when without an object, so Rails will only set the Last-Modified header and...

...cleared automatically after each test. By including the following helper hooks your tests can call jasmine.fixtures to access a container that is emptied once the test concludes: beforeAll(function() { jasmine.fixtures...

...to load records and their associations in a fixed number of queries. This is called preloading or eager loading associations. By preloading associations you can prevent the n+1 query...

...order => 'created_at DESC', :include => :author) end end This controller action works until someone calls the action with a category containing a dot character. This will make ActiveRecord join the...

...both limited to a set of HTTP libraries listed below (as of 2022). Direct calls to Kernel#open or OpenURI#open_uri are not mocked and will trigger real network...

evilmartians.com

...even displays helpful flamegraphs for better visualization. Provides actionable insights like: Number of factory calls in each test and the time spent on each. Breakdown of associated records created unintentionally...

...know anything about the API internals. It feels more natural, that you don't call client internals from your models. Only the public methods like GithubClient::Client.new.users('makandra GmbH') or...

...virtual environment. (They are located in ~/.venv/your-environment-name/bin/). To leave your virtual environment, you may call deactivate. To enter your venv again later, you must source it again, as described above...

kernel.org

Now, another commit will be checked out. See if the issue persists and call git bisect good or git bisect bad, resulting in another commit being fetched and so...

...def log(message) message.each_line do |line| Rails.logger.info(line.rstrip) end end You can then call log with your multi-line string and each line will be tagged. To improve even...

...painfully slow RegExp text matching or add the normalize_ws: true option to every call of a Capybara finder. I suggest that you rather configure it globally, which also affects...

...window rendering effects added by a window manager, and browsers don't provide a callback that would allow to detect the end of windows size changing process. Capybara provides a...

...WebDriverError, 'Switch to desired window before changing its size' unless handle == :current # Chromedriver API call named "set_window_rect" set_window_rect(width: width, height: height) end end

...archived => false) authors = posts.traverse_association(:author) You can traverse multiple associations in a single call. E.g. to turn a relation of posts into a relation of all posts of their...

...inlined, because it is only used once. Let's use a similiar input, but call fn() twice: function fn() { if (a) { return 'foo' } else if (b) { return 'foo' } else {

...console.log(o()) Note how: The function remains in the compressed output, as it is called more than once. The function name has been shortened to o, as it is not...

...additional scripting. While you may bind to the window's resize event, that might call your event listener many times. A better way is to subscribe to changes of the...

...def helper_method 42 end end World(Helpers) features/step_definitions/step.rb Then /^the helper method is called$/ do expect(helper_method).to eql(42)

news.ycombinator.com

...s encrypted password hash, salt and KMS key ID from the database. Make a call to KMS to decrypt the hash (KMS internally stores the corresponding private key but never...

...get exposed either. The only way to decrypt something is to make an API call to KMS. Thus, the only valid attack really is if the attacker is able to...

...pages, you should use tel: links so smartphone users can click those numbers to call someone. Here is a small helper method that you can use to simplify this:

...code (sometimes used when combining international and local numbers, see example below) as the called number should not include that zero. def tel_to(text) groups = text.to_s.scan(/(?:^\+)?\d+/) if groups.size...

Browsers blocks abusable JavaScript API calls until the user has interacted with the document. Examples would be opening new tab or start playing video or audio. E.g. if you attempt...

...to call video.play() in a test, the call will reject with a message like this: NotAllowedError: play() failed because the user didn't interact with the document first. https://goo.gl...

makandra dev
api.rubyonrails.org

...well as to query the record for registered errors. This object is returned when calling .errors: errors = @user.errors # => # Here are some helpful messages of its API: [ ] Returns an array of...

...Will retrieve the error message from the locale files. get( ) (Almost) an alias of []. Calls messages[ ] and returns an array of error messages for that attribute. include?( ) Returns whether there...