This project is archived and is in readonly mode.

#5110 ✓invalid
Lee Irving

Dirty Attributes and string manipulation

Reported by Lee Irving | July 14th, 2010 @ 09:34 AM

Just found what I believe is a bug.

With ActiveRecord modify the value of a string field with



@project.title[0] = "h"




This means that saving the record does not write the change.

Work around is

title = @project.title.clone

title[0] = "h"

@project.title = title



Comments and changes to this ticket

  • Ivan Torres (mexpolk)

    Ivan Torres (mexpolk) July 14th, 2010 @ 03:11 PM

    • Tag changed from rails 2.3.8, activerecord, dirty to rails 2.3.8, activerecord, dirty, rails3

    You're right, the strangest thing is that the original value is lost:

    @project.title_was => "helloWorld"

    Also this affects Rails 3

  • Ivan Torres (mexpolk)

    Ivan Torres (mexpolk) July 14th, 2010 @ 04:54 PM

    Doing some tests it turns out that if the String instance is the same, then the change is not detected. If the string is another instance it works as expected:

      # This wont work
      => "Rails"
      @project.title << " test"
      => "Rails test"
      => "Rails test"
      => false
      # This works
      @project.title += " test"
      => "Rails test"
      => "Rails"
      => true
  • Neeraj Singh

    Neeraj Singh July 29th, 2010 @ 02:19 PM

    • State changed from “new” to “invalid”
    • Importance changed from “” to “Low”

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>