...concept worked really good. Here are two points that were extraordinary compared to normal Rails project with many UI components: Having a Rails application, that has no UI components (only...
...to look up different before you need to integrate an API component into your Rails application. REST API vs. GraphQL It is worth to consider whether you want to have...
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.
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...
If you use webpacker in your Rails application, and you have completely disabled Sprockets, you might get the following error when trying to deploy: Rails assets manifest file not found...
...This happens inside the deploy:assets:backup_manifest task. This task comes from capistrano-rails. It is build for Sprockets and does not work with Webpacker out of the box...
To offer files for download, use send_file. def download(file) send_file file.path, :disposition => 'attachment' end
Rails supports alert and notice as default flash types. This allows you to use these keys as options in e.g. redirect_to and as a helper in views e.g. <%= notice...
...reload the page, log into the site and reload the cookie information site. For Rails powered sites, you should see a cookie named '_your_site_session' and -- depending on your...
...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...
...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
When working with times and dates in Rails applications, you need to deal with the following problem: In Rails, Time objects have a time zone. You can get the zone...
...just stores the literal string "2010-05-01 12:00:00". That means that Rails must make assumptions about timestamps loaded from and written to MySQL. Rails has two completely...
...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...
...capable of caching images. (FYI, here's how to do the upload all manually.) Rails setup Build these models: class Gallery < ActiveRecord::Base has_many :images, dependent: :destroy accepts_nested...
...connect a record to an already uploaded file = image_form.hidden_field :file_cache # Used by Rails to distinguish new from existing records = image_form.hidden_field :id # Used by Rails to know when...
It sometimes happen that a database dump, that would want to insert into your development database, does not match the...
The information in this card is only relevant for Rails 2.3-era apps. This note gives a quick introduction into caching methods (page caching, action caching and fragment caching) in...
...rails and describes some specific problems and solutions. The descriptions below are valid for Rails 2 and 3. Recently, caching with timestamp- or content-based keys has become more popular...
...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:
...decide to open a file directly instead of having to save it first. For Rails >= 3.2 Simply put your mime types in config/initializers/mime_types.rb. send_file will take care of everything...
For Rails < 3.2 Put your mime types in config/initializers/mime_types.rb. Additionally, tell send_file to use them (for example like this): file = @attachment.file.path file_extension = File.extname(file)[1..-1]
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...
In Ruby on Rails, all the routes of a given application can be found within the config/routes.rb file. You add more and more routes in this file as your project...
...important to find a way to order and maintain your routes. See: Clean your Rails routes: grouping Sometimes the routes.rb grows very fast and each line adds more confusion to...
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...
Using ActiveRecord's #signed_id and .find_signed methods you can create URLs that expire after some time. No conditionals...
Instead of cobbling together default settings in several different places as the issues arise, you can define them application-wide...
...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...
If a model inherits from others or uses many concerns / traits, it might be hard to see in the code...
The Rails logger will store its content in a buffer and write it into the file system every 1000 lines. This will come back to bite you when using Rails.logger.info...
...environments auto_flushing is set to write after each line. On production environments the Rails logger writes only every 1000 lines -- and not upon shell or script termination as you...