Friday, July 26, 2013

Solving ActiveRecord::ReadOnlyRecord in Rails 3


When you pass an SQL fragment to a finder, join or named scope, ActiveRecord returns read-only results by default.

Use readonly(false) in your queries to force that results are writable. Ex:

(Rails 3)
User.joins("INNER JOIN `cars` ON `cars`.`user_id` = `users`.`id` AND `cars`.`colour`  = 'electric blue'").readonly(false)

1 comment:

  1. Are you looking to make money from your visitors by running popup ads?
    In case you are, did you try using Clickadu?

    ReplyDelete