title: Ruby on Rails undefined method `each' for #<String:0x7efa908> Error
body: <p>I was trying to go through a string array in html, but get "undefined method `each' for #" error.
  <a href="https://i.stack.imgur.com/TqKlO.png" rel="nofollow noreferrer">Error image</a></p>
  
  <p>Here is the class definition for Planet class</p>
  
  <pre><code> class CreatePlanets &lt; ActiveRecord::Migration[5.0]
    def change
      create_table :planets do |t|
        t.string :name, null: false
        t.string :image, null: false
        t.string :description, array: true, default: '{}'
        t.timestamps
      end
    end
  end
  </code></pre>
  
  <p>Here is the html page</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;&lt;%= @planet.name %&gt;&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;h1&gt;&lt;%= @planet.name %&gt;&lt;/h1&gt;
      &lt;%= image_tag @planet.image %&gt;
      &lt;ul&gt;
          &lt;% @planet.description.each do |x| %&gt;
          &lt;li&gt;&lt;%= x %&gt;&lt;/li&gt;
          &lt;% end %&gt;
      &lt;/ul&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Here is how I migrated it </p>
  
  <pre><code>p1 = Planet.create(name: "Sun", image: "/../assets/images/sun.jpg", description: ["The center of the solar system and the only star in solar system.", 
  "Due to its huge mass, other planets in solar system form radiant power between sun and itself, maintaining the rotation around sun", 
  "The surface temperature is said to be about 6000 degree celcius."])
  </code></pre>
  
  <p>At first, I tried default: [] in the class definition, but it fails, so I changed it to '{}'. If someone knows how to deal with this problem in either way, please let me know. </p>
  
  <p>Thank you.</p>
  
  <hr>
  
  <p>Edited:</p>
  
  <p>After I tried @planet.description.lines.each, the output changes to this. <a href="https://i.stack.imgur.com/f4sS9.png" rel="nofollow noreferrer">Current Output</a></p>
  
  <p>Which has the lists on the same line and also include the [] which should be the outer container of the array</p>
  
  <hr>
  
  <p>Update:</p>
  
  <p>Now I changed CreatePlanets class to </p>
  
  <pre><code> class CreatePlanets &lt; ActiveRecord::Migration[5.0]
    def change
      create_table :planets do |t|
        t.string :name, null: false
        t.string :image, null: false
        t.text :description
        t.timestamps
      end
    end
  end
  </code></pre>
  
  <p>My seeds.rb </p>
  
  <pre><code>p1 = Planet.create(name: "Sun", image: "/../assets/images/sun.jpg")
  p1.description.push("The center of the solar system and the only star in solar system.", 
      "Due to its huge mass, other planets in solar system form radiant power between sun and itself, maintaining the rotation around sun", 
      "The surface temperature is said to be about 6000 degree celcius.")
  p1.save
  </code></pre>
  
  <p>My Planet class</p>
  
  <pre><code>class Planet &lt; ApplicationRecord
      serialize :description, Array
  end
  </code></pre>