Specify these gem versions in your Gemfile: gem 'cucumber', '~> 1.3.0' gem 'cucumber-rails', '= 0.3.2' # max version for Rails 2 gem 'capybara', '< 2' # capybara 2+ requires Rails 3 gem 'mime-types...

...SHA:EDH-RSA-DES-CBC-SHA:EDH-DSS-DES-CBC-SHA | To make your Rails application use SSL, modify config/database.yml and add this: sslca: /path/to/mysql-ssl-ca-cert.pem Ensure only encrypted connections are...

...development, you might get an ActiveRecord::EnvironmentMismatchError when trying to replace the database (like rails db:drop, rails db:schema:load). $ rails db:drop rails aborted! ActiveRecord::EnvironmentMismatchError: You are...

...sure you want to continue, first set the environment using: bin/rails db:environment:set RAILS_ENV=development Starting with Rails 5, the ar_internal_metadata database table was introduced:

ActionMailer per default uses http as protocol, which enables SSL-stripping. When a logged-in user follows an http link...

tl;dr You should decouple migrations from models by embedding models into the migration. To use STI in this scenario...

You can use record.send(:update_without_callbacks) or record.send(:create_without_callbacks) This can be used as a lightweight alternative to machinist's make or FactoryGirl's create...

...return the object, so you might want to do record = Record.new.tap(&:create_without_callbacks) Rails 3 Rails 3 no longer comes with update_without_callbacks or create_without_callbacks. There...

...not work with complex sorting constraints and may even silently create malformed SQL for rails < 5. Take a look at this query which orders by the maximum of two columns...

...SELECT "pages".* FROM "pages" ORDER BY GREATEST(pages.published_from_de, pages.published_from_en) DESC Rails 4 Rails 4 will not immediately raise but creates malformed SQL when trying to use...

makandra dev

...and install RubyGems yourself. Install Bundler sudo gem install bundler Put bundler on a Rails 2.3 project Follow the instructions on bundler.io You should have patched your boot.rb

...reads Gemfile and builds Gemfile.lock with all dependencies etc. If you see "Missing the Rails 2.3.8 gem." you forgot to bundle Rails. If you see "Missing the mysql gem", bundle...

makandra dev

...them, this is fortunately made very easy if you use compass. Simple example for Rails 3+ Let's assume you have two images app/assets/images/layout/blue-button.png, and .../blue-button-hover.png and the following sass...

...not there already, add this to the :assets group in your Gemfile: gem 'compass-rails' gem 'oily_png' Run bundle install. Add a config/compass.rb with the following content:

...possible to access Rails config (for example secrets) from within your webpack bundles, thanks to rails-erb-loader. When using webpacker, the setup is like this: Install rails-erb-loader...

...yarn add rails-erb-loader Add this to your config/webpacker/environment.js: environment.loaders.prepend('erb', { test: /\.erb$/, enforce: 'pre', use: [{ loader: 'rails-erb-loader', }] }) Start using erb. For example, in a file api_config.js.erb...

Watch out when saying something like 1.year in Rails. The result is not a Fixnum and can cause unexpected errors when the receiving end expects a Fixnum. While anything from...

...seconds to months are Fixnums, a year is a Float in Rails -- when called on a Fixnum itself: >> 10.seconds.class => Fixnum >> 2.minutes.class => Fixnum >> 24.hours.class => Fixnum >> 28.days.class => Fixnum >> 9.months.class => Fixnum >> 1.year.class

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.

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.

kukicola.io

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

github.com

bower-rails is a great solution for managing vendored assets in your Rails app. It feels especially much more convenient and easier to update assets when going this way.

...rails generates a Bowerfile that works much like the Gemfile you're used to. Just specify your dependencies and run rake bower:install. You can find available packages here.

medium.com

Root Insurance runs their application as a monolithic Rails application – but they've modularized it inside its repository. Here is their approach in summary: Strategy Keep all code in a...

...merges and deploys across N repos. Other resources https://www.airpair.com/ruby-on-rails/posts/ruby-on-rails-the-modular-way https://engineering.gusto.com/building-toward-a-modular-monolith https://railsconf.com/2020/video/vladimir-dementyev-between-monoliths-and-microservices

...the same routes, the controller paths will be different, though. In the first example rails will expect to find a Users::SignUpsController in the subdirectory controllers/users/sign_ups_controller.rb, but there has to...

...first example of this card (resource :report, only: :show, controller: 'projects/report'). Solution for legacy Rails versions What you can do instead is simple re-use the :projects symbol as both...

...you need to, probably your whole application should be split up. Split it anyway Rails::Engine looks at config.paths['config/routes.rb'] and registers its value with app.routes_reloader. This means you...

...then require them. However, I recommend to put any routing files into config/routes/: # config/routes/example.rb Rails.application.routes.draw do resources :example end After creating your routing files, tell Rails how to find them...

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

You might have some trouble running a Rails LTS 2 app with MySQL 5.7. If you don't want to hack Mysql 5.6 into your modern Ubuntu or use the...

...try MariaDB 10.x. MariaDB 10.x should work with both old and new Rails applications. Switch to MariaDB Remove MySQL: sudo apt remove mysql-common mysql-client mysql-server...

github.com

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

Note that this seems to affect only recent Rails 2 versions. You will not encounter this until you are writing to the cookie more than once, but when doing so...

Solution This seems to be a bug in Rails, the CookieStore (for sessions) or Rack::Utils.set_cookie_header -- I did not bother looking closer. My problems went away...

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

Yesterday, Rails fixed a security issue (CVE-2014-3514) in Rails 4+. It was possible to use .where or .create_with to bypass Rails' Strong Parameters: user.blog_posts.create_with...

...know .create_with existed, have a look at the API. How this applies to Rails 3 In Rails 3, Strong Parameters did not exist, yet. Instead, you used mass assignment...