title: String to Serialized Array? (nr. 2)
body: <p>i'm trying to add an before filter to manipulate user input:</p>
  
  <pre><code>class FormField &lt; ActiveRecord::Base
    attr_accessible :field_type, :name, :field_options
    serialize :field_options, Array
    before_validation :update_field_options
  
    def update_field_options
      begin
          self.field_options = self.field_options.split(/\,/).map(&amp;:strip)
        rescue ActiveRecord::SerializationTypeMismatch
          errors.add_to_base("Die Optionen bitte mit Kommata trennen)")
          false
      end
    end
  end
  </code></pre>
  
  <p>when i try to create a record with "1,2,3" it does not work (ActiveRecord::SerializationTypeMismatch).</p>
  
  <p>migration is:</p>
  
  <pre><code>t.string :field_options, :null =&gt; true
  </code></pre>
  
  <p>not sure what i do wrong here. if i change the before filter to:</p>
  
  <pre><code>self.field_options = [1,2,3]
  </code></pre>
  
  <p>it works, it seems that i can't access the self.field_options, but i can set them.....</p>
  
  <pre><code>logger.warn { "field_options #{ self.field_options }" }
  </code></pre>
  
  <p>does not output anything, not even "field_options", self gives me: </p>
  
  <p>similar to:</p>
  
  <p><a href="https://stackoverflow.com/questions/4711334/string-to-serialized-array">String to Serialized Array?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/5156900/ruby-on-rails-3-serialize-array-mismatched-class-bafflement">Ruby on Rails 3 - Serialize Array Mismatched Class Bafflement</a></p>
  
  <p>LOG:</p>
  
  <pre><code>Started POST "/global/form_fields?format=" for 127.0.0.1 at Sun Mar 20 17:50:00 +0100 2011
    SQL (3.8ms)  describe `shift_categories_users`
    SQL (3.9ms)  describe `roles_users`
    Processing by Global::FormFieldsController#create as 
    Parameters: {"form_field"=&gt;{"name"=&gt;"rails verion", "field_options"=&gt;"1,2,3", "field_type"=&gt;"select"}, "commit"=&gt;"Create Form field", "authenticity_token"=&gt;"nTmPr1H3Ilp6eRqLq/9Gd0JZx7wAw0lHqGlMBEq74HU=", "utf8"=&gt;"✓"}
    User Load (5.0ms)  SELECT `users`.* FROM `users` WHERE `users`.`id` = 261 LIMIT 1
    SQL (0.9ms)  BEGIN
    SQL (0.4ms)  ROLLBACK
    Account Load (1.6ms)  SELECT `accounts`.* FROM `accounts` WHERE `accounts`.`subdomain` = 'expertcloud' LIMIT 1
    ConfigOption Load (1.8ms)  SELECT `config_options`.* FROM `config_options` WHERE `config_options`.`name` = 'headline' AND (`config_options`.account_id = 82) LIMIT 1
  DEPRIATION WARNING - make sure you use it in the correct context. user.admin? use user.role?(:admin) insted
  DEPRIATION WARNING - make sure you use it in the correct context. user.admin? use user.role?(:admin) insted
    SQL (3.1ms)  describe `roles_users`
    Role Load (2.0ms)  SELECT `roles`.* FROM `roles`
    Role Load (2.0ms)  SELECT * FROM `roles` INNER JOIN `roles_users` ON `roles`.id = `roles_users`.role_id WHERE (`roles_users`.user_id = 261 ) LIMIT 1
  Rendered shared/_options.html.haml (73.3ms)
    CACHE (0.0ms)  SELECT `config_options`.* FROM `config_options` WHERE `config_options`.`name` = 'headline' AND (`config_options`.account_id = 82) LIMIT 1
    Role Load (1.2ms)  SELECT `roles`.* FROM `roles` INNER JOIN `roles_users` ON `roles`.id = `roles_users`.role_id WHERE `roles`.`name` = 'admin' AND (`roles_users`.user_id = 261 ) LIMIT 1
    SQL (2.9ms)  describe `shift_categories_users`
    Plan Load (1.8ms)  SELECT `plans`.* FROM `plans` WHERE `plans`.`id` = 4 LIMIT 1
  Rendered shared/_navigation.html.haml (179.3ms)
  Rendered shared/_header.html.haml (269.9ms)
  Rendered shared/_footer.html.haml (1.1ms)
  Rendered global/form_fields/new.html.haml within layouts/application (1141.4ms)
  Completed 200 OK in 1354ms (Views: 1231.8ms | ActiveRecord: 33.0ms)
  </code></pre>
  
  <p><strong>EDIT</strong>
  in the console:</p>
  
  <pre><code> FormField.create!(:field_options =&gt; "1,2,3")
  </code></pre>
  
  <p>and if i try to debug it in the model with:</p>
  
  <pre><code>puts "SPLIT #{ self.field_options }"
  puts "SPLIT #{ self.inspect }"
  </code></pre>
  
  <p>the error appears during reading the <strong>self.field_options</strong> (which is "1,2,3")</p>