When logging in Rails, you can use the log_tags configuration option to add extra information to each line, like :request_id or :subdomain. However, those are only valid inside...

...log entries which are mixed together. Welcome to debugging hell. You want something like Rails' :request_id tagging. This can easily be achieved through a Sidekiq middleware as follows.

Add deprecation warnings and their solution or link to available solutions. Global access to Rake DSL methods is deprecated. Please...

Run bundle update cucumber capybara cucumber-rails to update to the newest versions. Backup your features/support/path.rb to be able to add your own paths again after the cucumber installation script...

...your features/support/env.rb file to be able to reintegrate parts like your blueprints setup: ENV["RAILS_ENV"] ||= "cucumber" require File.expand_path(File.dirname(__FILE__) + '/../../config/environment') require 'spec/support/blueprints' Run $ rails generate cucumber:install...

ariejan.net

Rails understands a :limit options when you create columns in a migration. Its meaning depends on the column type, and sometimes the supplied value. The documentation states that :limit sets...

kukicola.io

Using ActiveRecord's #signed_id and .find_signed methods you can create URLs that expire after some time. No conditionals...

...token authenticity" even if csrf token is present? As :domain => :all is set in Rails 3, local session cookies seem not to be set unless you specify a top-level...

Solutions Use a dns wildcard service like lvh.me and set :domain => 'lvh.me' if Rails.env.development? Then you can access your local server with lvh.me:3000 or anysubdomain.lvh.me:3000. Another way is, to...

Rails flashes (FlashHash) track a list of used keys, which is not respected when comparing flash hashes. This does not concern you under most circumstances. Basics When ActionController picks up...

...method which checks for that: ActionController::Flash::FlashHash.class_eval do # This is from a Rails 2 project. For Rails 3, say: # ActionDispatch::Flash::FlashHash.class_eval do def same?(other_flash...

...setting the :x_sendfile option to true. This option is activated by default for Rails 3, so you need to understand this. What this option does is not to send...

...as a new response header: X-Sendfile: /opt/www/awesome-project/shared/downloads/image.png When the response comes back from Rails to Apache for delivery, Apache will detect that header and replace the empty response body...

...has to wait until the thread of one of the workers is free. Threads Rails is thread-safe since version 4 (note that not all gems are thread-safe). This...

...for the related config/puma.rb: workers Integer(ENV['WEB_CONCURRENCY'] || 2) threads_count = Integer(ENV['RAILS_MAX_THREADS'] || 5) Note: Having multiple workers in development and tests might cause unexpected issues...

tl;dr: Upgrade the gem to at least 4.0.1 When you use rspec_rails in a version < 4 with Rails 6.1 you may encounter an error like this: Failure/Error:

...expect(actor).to be_valid end end But the error came from rspec_rails itself. I found this issue on GitHub, which is solved in rspec_rails 4.0.1.

You have to specify the environment with -e env_name or RAILS_ENV=env_name if you want to run a script on the server. at Rails 2 it's...

bundle exec script/runner -e env_name path/to/script.rb argument1 argument2 ... at Rails 3 it's rails runner RAILS_ENV=env_name bundle exec rails runner path/to/script.rb argument1 argument2...

...locale/de/app.po for every locale you want to use use method "_" like _('text') in your rails code run rake gettext:find to let GetText find all translations used translate messages in...

...locales = [ 'en', 'de' ] FastGettext.add_text_domain('app', :path=>'locale', :type=>:po) FastGettext.text_domain = 'app' Rails::Initializer.run do |config| # Versionsnummern selber rausfinden: config.gem 'spreadsheet', :version => '=0.6.4.1' config.gem "fast_gettext", :version...

...all styling inline, which means you'll have to do your styling inline. For Rails applications, you can use Roadie or premailer, which lets you keep your well-structured CSS...

...passive maintenance mode, we go with premailer: Include premailer in your Gemfile: gem 'premailer-rails' In your ApplicationMailer define the mailer layout: layout 'mailer' To get the mailer stylesheet (and...

It sometimes happen that a database dump, that would want to insert into your development database, does not match the...

You either have an old version of Mocha and an edge version of Rails 3.2, or you have a new version of Mocha and an old version of Rails. The...

...best solution is to update Mocha to the latest version and switch to Rails edge. If you are using shoulda-matchers or another gem that locks Mocha to an old...

Rails 5.2+ supports "verbose query logs" where it shows the source of a query in the application log. Normally, it looks like this: User Load (0.5ms) SELECT "users".* FROM...

...While there was an issue back in 2018 which can be resolved by upgrading Rails, this also happens when ActiveSupport's BacktraceCleaner is configured to not hide gems from the...

Plugins (and gems) are typically tested using a complete sample rails application that lives in the spec folder of the plugin. If your gem is supposed to work with multiple...

...versions of Rails, you might want to use to separate apps - one for each rails version. For best practice examples that give you full coverage with minimal repitition of code...

There is a nasty bug in all version of Rails 2 and some versions of Rails 3.x where two chained scopes with hash conditions on the same attribute would...

...what a user may see or change. Workaround If you are using an affected Rails version and cannot switch to a fixed version, you can use this manual workaround.

github.com

...Gruff for easily plotting graphs. It is written in pure Ruby and integrates with Rails applications. It provides features as automatic sizing of dots and lines (the more values, the...

...restart your development server.) Usage This is a common example for graph generation in Rails. Note that you have many configuration options at hand that are not documented. Github and...

github.com

Instead of cobbling together default settings in several different places as the issues arise, you can define them application-wide...

In Rails 5 you can say: ApplicationController.render( :template => 'users/index', :layout => 'my_layout', :assigns => { users: @users } ) If a Request Environment is needed you can set attributes default attributes or initialize a...

...host: 'example.org', https: false ) renderer.render( :template => 'users/index', :layout => 'my_layout', :assigns => { users: @users } ) In Rails 3 and 4 you can say: ApplicationController.new.render_to_string( :template => 'users/index', :layout => 'my_layout',

api.rubyonrails.org

Rails 5 (don't know about the others) comes with an initializer wrap_parameters.rb. Here you can tell rails to wrap parameters send to your controllers for specific formats into a...

...used to when you are dealing with form payloads. This is especially handy because Rails puts some stuff in the params which does not really belong there IMHO. For instance...

...in development. This is usually useful, but when you run into issues with the Rails autoloader, you should take a look at what it's doing. For me this was...

...of auto-loading classes inside a thread which caused the application to stop responding. Rails 4.x ActiveSupport::Dependencies includes logging support. It is easy to use: ActiveSupport::Dependencies.logger = Rails.logger...

...writing a piece of reusable code, you sometimes need to have separate code for Rails 2 and Rails 3. You can distinguish between Rails versions like this: if Rails.version...

...mind the quotes # Rails 2 code goes here else # Rails 3+ code goes here