title: Bulk insert using one model
body: <p>I'm trying to create a form using textarea and a submit button that will allow users to do bulk insert. For example, the input would look like this:</p>
  
  <pre><code>0001;MR A
  0002;MR B
  </code></pre>
  
  <p>The result would look like this:</p>
  
  <pre><code>mysql&gt; select * from members;
  
  +------+------+------+
  |  id  |  no  | name |
  +------+------+------+
  |   1  | 0001 | MR A |
  +------+------+------+
  |   2  | 0002 | MR B |
  +------+------+------+
  </code></pre>
  
  <p>I'm very new to Rails and I'm not sure on how to proceed with this one. Should I use <code>attr_accessor</code>? How do I handle failed validations in the form view? Is there any example? Thanks in advance.</p>
  
  <p><strong>Update</strong></p>
  
  <p>Based on <a href="https://stackoverflow.com/users/487906/missinghandle">MissingHandle</a>'s comment, I created a Scaffold and replace the Model's code with this:</p>
  
  <pre><code>class MemberBulk &lt; ActiveRecord::Base
  
    attr_accessor :member
  
    def self.columns
      @columsn ||= []
    end
  
    def self.column(name, sql_type = nil, default = nil, null = true)
      columns &lt;&lt; ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null)
    end
  
    column :data, :text
  
    validates :data, :create_members, :presence =&gt; true
  
    def create_members
      rows = self.data.split("\r\n")
  
      @member = Array.new
  
      rows.each_with_index { |row, i|
        rows[i] = row.strip
        cols = row.split(";")
  
        p = Member.new
        p.no = cols[0]
        p.name = cols[1]
  
        if p.valid?
          member &lt;&lt; p
        else
          p.errors.map { |k, v| errors.add(:data, "\"#{row}\" #{v}") }
        end
      }
    end
  
    def create_or_update
      member.each { |p|
        p.save
      }
    end
  end
  </code></pre>
  
  <p>I know the code is far from complete, but I need to know is this the correct way to do it? </p>