Skip to content
adamwong246 edited this page Mar 8, 2013 · 8 revisions

*Don't take this too seriously, this document is only for my benefit, it's all a work in progress, etc :-)

This plugin is intended to compliment the rails_admin export function. It is intended to allow the user to import data from a variety of file formats.

  1. CSV, delimited by comma. Should we support semi-colon and tab delimited CSV? Technically not CSV...
  2. JSON
  3. XML
  4. YAML *Note that this format is not supported by rails_admin_export (but it should be!)
  5. RSS *See section below

This particular fork also allows for the configuration of a 'key' field, which determines if a record is new, wherein a new record should be created, or if the record already exists and should only be updated.

Currently, the only working file format is comma delimited CSV files.

RSS

RSS files must be handled as a special case. Other file formats allow one to serialize data isomorphically. RSS, however, imposes a strict structure and therefore, a mapping between item fields must be established. For every <item> in an RSS file, there exists:

  1. The title of the item <title>
  2. A description of the item <description>
  3. A link to that item <link>
  4. A unique identifier <guid>
  5. The data published <pubDate>

Given a ActiveRecord

 create_table "posts", :force => true do |t|
    t.string   "post_title",                                     :null => false
    t.text     "post_body",                                      :null => false
    t.datetime "published_at"
    t.datetime "created_at"
    t.datetime "updated_at"
    t.datetime "edited_at",                                 :null => false
  end

This is how you might map records to RSS items

RailsAdminImport.config do |config| 
  rss_mapping do
      {
        :title => Proc.new{ |item| item.title  + item.published.to_s },
        :body => Proc.new{ |item| item.summary },
        :published_at => Proc.new{ |item| item.published }
      }
    end
end
Clone this wiki locally