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

*Don't take this too seriously, it's all a work in progress :-)

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, semi-colon and tab
  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 defined thus:

 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

an RSS mapping might appear thusly as pure Ruby code:

RailsAdminImport.config do |config| 
  config.model Post do
    rss_map[:post_title] => Proc.new{ |item| item.title  + Date.parse(item.pubDate) }
    rss_map[:post_body]  => Proc.new{ |item| item.description}
  end
end

or as a DSL

RailsAdminImport.config do |config| 
  config.model Post do
    rss_mapping do
      :post_title, item.title + Date.parse(item.pubDate) 
      :post_body, item.description
  end
end
Clone this wiki locally