...preprocessed: true end end Preprocess this version for all existing records bundle exec rails runner 'User.find_each { |user| user.avatar.variant(:preview).processed }' Use the new variant and deploy

leomayleomay.github.io

Your after_commit callbacks will not know about changes, as Rails discards them when committing. The linked article shows a clever trick to work around that: It uses an after...

...commit, and not after_save. Enqueueing a Sidekiq job is just one of them. Rails 5+ You can use saved_change_to_attribute? and previous_changes[:attribute] in after_commit...

...object-oriented scripting language Ruby rubymine 2018.3.2 jetbrains✓ classic The Most Intelligent Ruby and Rails IDE ... Switch channel and install most recent version: $ sudo snap refresh rubymine --channel=2018.2/stable...

...image running the headless Chrome (e.g. chrome:4444) The integration test is testing a Rails application (but it could be any other application, too) Start your integration test docker container...

where html_content can be replaced by one of the following commands: Rails body or response.body Capybara: page.driver.html.content page.body Webrat: Nokogiri::HTML(response.body).content The returned strings can...

stackoverflow.com

...Stefan', color: 'red'} ] names = users.collect do |user| user[:name] end If you're using Rails 5+, this example is covered by Enumerable#pluck (users.pluck(:name)). But with a little extension...

...up on the disk check table sizes by disk usage instead. Connect to a Rails database with bin/rails dbconsole -p...

web.archive.org

Rails 6.1 has a "strict loading" mode that forces the developer to preload any association they plan to use. Associations no longer load lazily. An error is raised when reading...

...For newer Ruby versions, use form_with_development_errors.rb. This monkey patches both form_for and form_with. Rails-XSS is required by default. So if your project doesn't support Rails-XSS...

...config.gem 'chunky_png', :version => '=0.8.0' create config/initializers/compass.rb (or copy from development repo): ^ require 'compass' rails_root = (defined?(Rails) ? Rails.root : RAILS_ROOT).to_s Compass.add_project_configuration(File.join(rails_root, "config...

^ This configuration file works with both the Compass command line tool and within Rails. Require any additional compass plugins here. project_type = :rails project_path = Compass::AppIntegration::Rails.root

RSpec Rails can automatically mix in different behaviors to your tests based on their type tag, for example enabling you to call get and post in specs with the tag...

If you require your Rails models manually, pay attention to the path you use. Unless you have to, don't do it at all. Background Consider these...

class Foo # something happens here end Now, when your environment is booted, Rails will automatically load your models, like User. In our example, when Foo gets loaded, it...

...for session hashes. Use update instead. Outline Let's assume you're modifying the Rails session. For simplicity, let's also assume your session is empty when you start (same...

...is the ActionController::Session::AbstractStore::SessionHash class (session is of that type in your Rails application, but also in Rack middleware): class SessionHash < Hash # ... def update(hash) load_for_write...

...use the String#strip_heredoc method from ActiveSupport. See Summarizing heredoc in ruby and rails for an example. Technically, it looks for the least indented line in the whole string...

Rails comes with grouped_collection_select that appears to be useful, but isn't. As an alternative, consider the flat_grouped_collection_select found below. It takes a third argument...

...like app/inputs/grouped_collection_select_input.rb (SimpleForm will pick it up automatically; if it does not, restart your Rails server) and use it in your form with that new :group_by option.

If you migrate a Rails application from Sprockets to Webpack(er), you can either transpile your CoffeeScript files to JavaScript or integrate a CoffeeScript compiler to your new process. This...

...This is why we don't use "transactional fixtures" in our Cucumber tests, which Rails by default uses to clean up the database after each test. Instead we use DatabaseCleaner...

Adding the asset cache directory to symlinked directories Popular asset managers for Rails are Sprockets and Webpacker. Both keep a cache of already compiled files that we're...

...you already have stored files in the old structure) Checklist: Using Carrierwave in a Rails project

github.com

...uses mocha. This note shows to use RSpec stubs and mocks instead. Rspec 1 / Rails 2 Put the following into your env.rb: require 'spec/stubs/cucumber' Rspec 2 / Rails 3

If you want to make your Rails application be capable of sending SMTP emails, check out the action mailer configuration section in the Ruby on Rails guide.

...in your environment or individually applied to an email generated in your mailer: # production.rb: Rails.application.configure do config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = smtp_settings end # test_mailer.rb def test_mail

Note that you cannot currently use Ruby 1.9.2 with Rails 2 applications that use RSpec, so don't upgrade if that is your setup. The rspec-rails gem has a...

...fatal bug that was only fixed for rspec-rails-2.x, which only supports Rails 3. There is no fix for the rspec-rails-1.3.x series of the gem...

Running rails server will start a local server that you can access via http://localhost:3000. When you are working on multiple web apps, they will likely set cookies with...