...load the dump successfully, i.e. restore data for all the tables it contained (including Rails' schema_migrations). However, it would not remove any extra tables that were not part of...
SOURCE foo.dump \i foo.dump Further reading How to setup Ruby on Rails with PostgreSQL Connect to a Rails database with bin/rails dbconsole -p...
...without changing the return value: def save_user user.save.tap do |saved| next unless saved Rails.log("User was created, we have #{user.count} users now!") end end save_user # User was created...
Pour color on your Rails console with awesome_print. Turn confusing long strings into formatted output. Have objects and classes laid out clearly whenever you need it. Put gem 'awesome...
...print', :group => :development into your Gemfile. Now on the Rails console you have the command ap that will give you a colored, formatted output of whatever you pass it. See...
.sort_by(&:last) .to_h end end Just paste that snippet into a Rails console and use #count_by now! Usage examples Number of email addresses by domain: > User.all.count...
...Article.all.count_by &:brand Note that the last simple example can also be achieved with Rails internals: Article.group(:brand).count. This translates to SQL, so it executes fast. However, grouping is...
...an unsubscribe token Each user needs a token that allows them to unsubscribe securely. Rails' signed_id works well for this: class FrontendUser < ApplicationRecord # ... def unsubscription_token return unless persisted...
...app/models/test.rb index eg3c1k1..843c0a2 31143 --- app/models/test.rb +++ app/models/test.rb @@ -19,6 +19,10 @@ module RoutingFilter path = Rails.root / 'app' + if true + + end + return path (1/1) Discard this hunk from worktree [y,n,q...
Params are tricky Testing for request params is a little tricky because Rails hides details about how HTTP works. In particular GET requests encode their params in the URL...
...your application perform with lots of data? Generate many records per table. Watch the Rails logs and query_diet to find areas of improvement. Reduce N+1 queries, preload associations...
When a user shares your content, a snippet with title, image, link and description appears in her timeline. By default...
...for every little thing. Jasmine is a purely client-side tool. It cannot ask Rails to render a view or access the database. Any HTTP calls must be mocked.
Tip Create the required DOM directly from your Jasmine spec. You cannot ask Rails to render a view. You can use Element#dispatchEvent() to emit events on a DOM...
While most Rails Apps are tied to at least one external REST API, machine-to-machine communication via GraphQL is less commonly seen. In this card, I'd like to...
...w[errors]) unless response.status.ok? parsed_response end def client headers = { 'Content-Type' => 'application/json', 'Authorization' => Rails.application.secrets.fetch(:linear_api_key), } HTTP.headers(headers) end end Writing data (Mutation) Performing GraphQL mutations is equally...
...will see less noise in your test output: if RSpec.configuration.files_to_run.count > 5 require "simplecov" SimpleCov.start 'rails' end See also How to use Simplecov to find untested code in a Rails project...
...you're not familiar with the pattern, read or re-read "New rules for Rails" from Growing Rails Applications in Practice (in our library) How to navigate between indexes, show...
...in webpack.config.js: { ... optimization: { minimize: true, minimizer: [ new TerserPlugin({ terserOptions: { ..., mangle: { properties: { regex: /^[_#]/ } } } }) ] } } Configuring Webpacker (Rails) To configure Webpack to mangle private properties, make a change to your Terser configuration in...
...like above: new(str, safe_level=nil, trim_mode=nil, eoutvar='_erbout') Difference between Rails mailer and ERB Rails mailer <% if true %> <%= 'bar' %> <% end %> <%= 'foo' %> <%= 'bar' %> bar foo bar
Generating a project README Finally: Support for modelling associations between models in your application model! Example: # lib/katapult/application_model.rb
quiet_assets helps with disabling asset pipeline log messages in the development log. When the gem is added, asset pipeline...
class Errormaster CoffeeIsOut = Class.new(StandardError) # is prettier than class CoffeeIsOut < StandardError; end end Reference such an error class with Errormaster...
We are changing our name from Hoptoad to Airbrake. You see, some folks much larger than us reached out and...
Now allows to list transition paths from and to arbitrary states.
How to write to the db 27,000 times in 24 seconds instead of 9 minutes.
Sometimes, you just need to shoot from the hip…or deploy your local changes without committing them. Put this snippet...
When rendering a partial with the :collection option, you are automatically provided with a counter variable inside the partial template...