...the sudo password with johndoe ALL=(ALL) NOPASSWD: ALL. # Run this script with e.g. `rails runner lib/scripts/benchmark.rb` require 'open3' # For debugging # Rails.logger = Logger.new(STDOUT) # ActiveRecord::Base.logger = Logger.new(STDOUT)

With this command you can initiate an application restart without touching restart.txt. Unlike touching restart.txt, this tool initiates the restart...

...you're done, check your changes by running rake routes. handle_unverified_request When Rails gets a request with wrong/missing CSRF-Token, it calls ApplicationController#handle_unverified_request and continues...

...processing the request!. Per default, the method only resets the Rails session, but since Clearance doesn't store its session there, you should delete the remember_token cookie. With Clearance...

...this requires the PP class from the pp gem. It is loaded in any Rails app already, but for plain Ruby you may need to require it.

...are libraries like morphdom (as used by Phoenix Liveviews) or idiomorph (as used by Rails' Turbo). It lets you write morphdom(node, newHtml) or Idiomorph.morph(node, newHtml) which will try...

...issues in specific scenarios. Why does this matter? Mocked time in tests Consider a Rails application where you use the remember_me feature of Clearance for authentication. The cookie for...

This is quite an edge case, and appears like a bug in Rails (4.2.6) to me. Update: This is now documented on Edgeguides Ruby on Rails: If you set the...

...resources. The spec looks very similar to how one would build an API with Rails and uses similar patterns. Even if you don't plan on supporting the whole spec...

...they won't change their mind. [1] We are not talking about the the Rails session hash here, although it is by default backed by a cookie without expiration...

...not rendered in controller specs. If you need it to happen, use: RSpec 1 (Rails 2): integrate_views RSpec 2 (Rails 3): render_views Note that you can't use...

...a command on all servers. bundle exec cap production app:run cmd='zgrep -P "..." RAILS_ROOT/log/production.log' Code # lib/capistrano/tasks/app.rake namespace :app do # Use e.g. to grep logs on all servers:

...cap production app:run_cmd cmd='zgrep -P "..." RAILS_ROOT/log/production.log' # # * Use RAILS_ROOT as a placeholder for the remote Rails root directory. # * Append ` || test $? =1;` to grep calls in order...

Put the line below in the respective env.rb file to make your action controllers raise an ActionController::UnpermittedParameters error when...

evilmartians.com

...building it yourself Also see the chapter "Owning your Stack" in the book Growing Rails Applications in Practice. Services Open-Source Maturity & Maintenance Certification Rubygems

blog.bigbinary.com

...posts"."user_id" = "users"."id" WHERE (posts.id > 10) Using includes usually works nicely, but Rails will apply some magic, as mentioned at the beginning of this card. This is subject...

...an alternative to PostgreSQL fulltext search A simple example with a GIN index in Rails for optimizing a ILIKE query

...at self.class.ancestors. For example: config.before do # stuff that_fancy_method if is_a? Spec::Rails::Example::ControllerExampleGroup # more stuff end Find out if you are in a spec that knows...

...s request and response, like helper specs or controller specs: if is_a? Spec::Rails::Example::FunctionalExampleGroup that_fancy_request_thing end Note that you should not check via something...

...is to to require all files in a specific diretory, using something like Dir.glob(Rails.root.join('lib/ext/**/*.rb')).each do |filename| require filename end However, this causes files to be required...

...behavior on different machines which are hard to debug. Simply add a .sort: Dir.glob(Rails.root.join('lib/ext/**/*.rb')).sort.each do |filename| require filename end Ruby 3 Ruby 3 Dir class sorts...

...does not apply to your "Background" steps How to set up database_cleaner for Rails with Cucumber and RSpec Before all in database transactions will fail

relishapp.com

...for example could be sped up more than 4 times by reusing a cached Rails application, and the tests for a video player we built could also be sped up...

When your Rails application offers downloading a bunch of files as ZIP archive, you basically have two options: Write a ZIP file to disk and send it as a download...

...Add zip_tricks to your Gemfile and bundle install. In your controller, include ZipTricks::RailsStreaming. You can then use the zip_tricks_stream method in controller actions to generated your...

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...

Webpacker can automatically create an icon font from SVG files, which is really handy. When you're using the asset...

...prevent this, you need to add ->{ uniq } as second argument to has_many (below Rails 4 it is a simple option: has_many :xyz, :uniq => true). Example

...model. Prefer to use a form model like User::RegistrationForm. Read our book Growing Rails Applications in Practice for details. Here is a test for the User model that automatically...