It sometimes happen that a database dump, that would want to insert into your development database, does not match the...
...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:
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...
...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...
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...
...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...
Using ActiveRecord's #signed_id and .find_signed methods you can create URLs that expire after some time. No conditionals...
...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
If a model inherits from others or uses many concerns / traits, it might be hard to see in the code...
Instead of cobbling together default settings in several different places as the issues arise, you can define them application-wide...
...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...
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...
...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]
Rails uses a CSRF token in forms and AJAX requests to verify a user request. Internally it compares the injected CSRF token of the form data with the CSRF token...
...the CSRF token from the form data. Here is a method that works for Rails 5.2. def decode_csrf_token(csrf_token) decoded_masked_token = Base64.strict_decode64(csrf_token)
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...
Any 404 error that is caused by something not found in your Rails app will render a nice message using your default layout. Similarly, you may catch and...
If you need to log to a file you can use Ruby's Logger class: require 'logger'
...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...
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...
...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...
...row becomes expensive The linked article shows how to create a partial index with Rails...
...prevent this, test for the right environment and place the JS-code afterwards: - if Rails.env.production? :javascript var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-XXXXXXXX-X']); _gaq.push(['_trackPageview...
See our new comprehensive guide for upgrading every Rails 2 version ever...