...ETag for responses that only differ in CSRF tokens or CSP nonces. By default Rails uses Rack::ETag to generate ETag headers by hashing the response body. In theory this...
...would enable caching for multiple requests to the same resource. However, since most Rails application layouts insert randomly rotating CSRF tokens and CSP nonces into the HTML, two requests for...
...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...
...repositories. It's basically "Open Source Development 101". Way back in mid-2007, when Rails 1.2 was the new hotness and GitHub was still a year away from crawling out...
...method's source code If your Gemfile comes with method_source (a dependency of Rails 7+), you can can inspect the source code directly using the Method#source method:
...generated for associations. Warning Don't use query_attribute on associations. In case of Rails 7 you are getting an error. In Rails 6 this method is always responding with...
...saved to database directly as the the dumped object was not marked dirty, thus rails does not see the need to save it, even if the object is not present...
...add the following tests to test suites: # Make sure to require the previews Dir[Rails.root.join('spec/mailers/previews/*.rb')].each { |file| require(file) } ActionMailer::Preview.all.index_with(&:emails).each do |preview, mails|
tl;dr: Always have your attachment path start with :rails_root/storage/#{Rails.env}#{ENV['RAILS_TEST_NUMBER']}/. The directory where you save your Paperclip attachments should not look like this: storage/photos/1...
...storage/test/photos/1/... storage/test/photos/2/... storage/test/attachments/1/... storage/test/attachments/2/... storage/test2/photos/1/... storage/test2/photos/2/... storage/test2/attachments/1/... storage/test2/attachments/2/... In order to implement this, make Rails.env and ENV['RAILS_TEST_NUMBER'] part of your path template: has_attached_file :attachment, :path...
Webpack is the future. We're using it in our latest Rails applications. For tests, we want to compile assets like for production. For parallel tests, we want to avoid...
...Dir.empty?(public_output_path) end delegate :public_output_path, to: :config private def test? Rails.env.test? end def parallel_tests? test? && !!parallel_tests_number end def parallel_tests_number
Test one codebase against multiple sets of gem dependency sets (e.g. Rails 4.2, Rails 5.0). Test one codebase against multiple Ruby versions (e.g. Ruby 2.1.8, Ruby...
...possible dependency permutations (Ruby, gem set, database type). Manually exclude incompatible dependency permutations (e.g. Rails 5.0 does not work with Ruby 2.1). Let developers enter their local credentials for MySQL...
...for that. The reason why you never had to write this line is that Rails does this for you when it boots the environment. That also means that if you...
...have an embedded Rails app in your spec folder (like has_defaults), and you boot its environment, it should call Bundler.require for you and you don't need to require...
...have to run a separate process. # You'll also benefit from code reloading. if Rails.env.development? require 'sidekiq/testing' Sidekiq::Testing.inline!
...our output will be more verbose than when we only need support modern browsers. Rails 5.1+ projects often use Webpacker to preconfigure the Webpack pipeline for us. The default configuration...
...mocked with Timecop. To integrate those two, we include and activate timemachine.js in our Rails layout whenever we see that Timecop is mocking the time: - if defined?(Timecop) && Timecop.top_stack...
...following project: ruby -v ruby 1.8.7 bundler -v Bundler version 1.13.7 gem -v 1.8.30 rails -v Rails 3.2.22.1 Running specs or features resulted in: uninitialized constant Gem::LOADED_SPECS_MUTEX...
...previous settings described in Maximum version of Rubygems and Bundler for Ruby 1.8.7 and Rails 2.3 (even the rails version was rails 3.2 and not 2.3) seems not to work...
...OVER() AS full_count FROM (/* some complicated subquery */) posts LIMIT 20 OFFSET 100; In Rails with will_paginate you might use it like this: posts = scope_complicated_scope.select('posts.*, COUNT(*) OVER() AS...
...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...
...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...
...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...
...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...
...want something similar, so we define our own helper object: let :helper do Spec::Rails::Example::HelperExampleGroup::HelperObject.new.tap do |helper| helper.send :extend, LayoutHelper end end it 'should work' helper.title('Hello...
helper.instance_variable_get('@content_for_title').should == 'Hello World' end This applies to Rails 2. Maybe RSpec 2 / Rails 3 are smarter...
...Note.all.preload(:attachments).ids.size # => 8 Note I created a bug report for this in the Rails project: https://github.com/rails/rails/issues/46455
...up on the disk check table sizes by disk usage instead. Connect to a Rails database with bin/rails dbconsole -p...