title: Creating new Records on initialization in Rails
body: <p>I have searched through similar posts with similar titles, but can't figure out the answer. It is a newb question, apologies in advance.</p>
  
  <p>I want to add records to my database on initialization, to continually check what videos I have in my local directory. Please note, this application is ONLY for local development, not for deployment.</p>
  
  <p>What silly mistakes am I making here?</p>
  
  <pre><code>saved_videos_controller.rb
  
  Dir.glob("#{ROOTPATH}/lib/videos/*.mp4").each do |item|
      size = File.size(item)  
      @extension = File.extname(item)
      name = File.basename(item)
      @name = name[0...name.index(@extension)]
      @rootpath = item[0..item.rindex('/')]
  
      SavedVideo.create(:name =&gt; @name,:extension =&gt; @extension) unless size==0 
  end
  
  def index
      @saved_videos = SavedVideo.all
  end
  
  saved_video.rb
  
  class SavedVideo &lt; ActiveRecord::Base
     include ActiveModel::Model
      attr_accessor :filename, :extension
      validates :filename, :extension, presence: true
  
      def self.name
      @name
      end
  
      def self.extension
       @extension
      end
  end
  
  schema.rb
      ActiveRecord::Schema.define(version: 20150207072508) do
  
    create_table "saved_videos", force: true do |t|
      t.string   "filename"
      t.datetime "created_at"
      t.datetime "updated_at"
      t.string   "extension"
  end
  </code></pre>