Understand ActiveRecord::ReadOnlyRecord error
When you load a record with find options that have SQL fragments in :select
or :joins
, ActiveRecord will make that record read-only. This is a protective measure by Rails because such a record might have some additional attributes that don't correspond to actual table columns.
You can override that precaution by appending :readonly => false
to affected find options or scope options.
Related cards:
Mysql::Error: SAVEPOINT active_record_1 does not exist: ROLLBACK TO SAVEPOINT active_record_1 (ActiveRecord::StatementInvalid)
Possible Reason 1: parallel_tests - running more processes than features
If you run old versions of parallel_tests with m...
Rails: How to check if a certain validation failed
If validations failed for a record, and you want to find out if a specific validation failed, you can leverage ActiveModel's error objects.
You rarely need this in application code (you usually just want to print error messages), but it can be u...
ActiveRecord::RecordNotFound errors allow you to query the :name and :id of the model that could not be found
ActiveRecord::RecordNotFound
errors provide quite meaningful error messages that can provide some insight on application details. Consider the following:
ActiveRecord::RecordNotFound: Couldn't find Organisation::Membership with 'id'=12 [WHE...
Simple Form: Rendering errors without an appropriate attribute
Usually you add errors to :base in ActiveRecord, in case no appropriate attribute could be used to add the error.
Simple Form...
ActiveRecord: Overwriting a setter causes trouble with attributes depending on each other
Undeterministically I got a nil
error on saving the object caused by the random order of hash elements of the params hash.
class Feedback
belongs_to :user
def role=(value)
@role = value
self.email = find...
ActiveRecord::StatementInvalid: Mysql2::Error: closed MySQL connection
I recently experienced the error ActiveRecord::StatementInvalid: Mysql2::Error: closed MySQL connection
. Apparently this happens when there is a timeout during query execution. In order to fix this you can reconnect to your db.
Therefore either...
Understanding the Selenium error "Modal Dialog Present"
So your Cucumber feature sometimes dies with this exception:
Modal Dialog Present (Selenium::WebDriver::Error::UnhandledAlertError)
As a seasoned Selenium vetaran you are used to misleading error messages. Hence you might be surprised ...
Raising JavaScript errors in Ruby E2E tests (RSpec, Cucumber)
A JavaScript error in an E2E test with Selenium will not cause your test to fail. This may cause you to miss errors in your frontend code.
Using the BrowserConsole
helper below you can check your browser's error console from your E2E tests.
...
esbuild: Make your Rails application show build errors
Building application assets with esbuild is the new way to do it, and it's great, especially in combination with Sprockets (or Propshaft on Rails 7).
You might be missing some convenience features, though.
Here we cover one specific issue:
Once y...