2016-12-01 48 views
0

我在我的Rails應用程序下面的模式:如何從一個數據庫表中的數據導入到鐵軌模型

ActiveRecord::Schema.define(version: 20161020060112) do  
create_table "authors", force: :cascade do |t| 
    t.string "name" 
    t.datetime "created_at", null: false 
    t.datetime "updated_at", null: false 
end 

create_table "languages", force: :cascade do |t| 
    t.string "name" 
    t.datetime "created_at", null: false 
    t.datetime "updated_at", null: false 
end 

create_table "quotes", force: :cascade do |t| 
    t.string "title" 
    t.date  "date" 
    t.string "body" 
    t.datetime "created_at", null: false 
    t.datetime "updated_at", null: false 
    t.integer "author_id" 
    t.integer "language_id" 
    t.integer "source_id" 
    t.index ["author_id"], name: "index_quotes_on_author_id" 
    t.index ["language_id"], name: "index_quotes_on_language_id" 
    t.index ["source_id"], name: "index_quotes_on_source_id" 
end 

    create_table "source_types", force: :cascade do |t| 
    t.string "name" 
    t.datetime "created_at", null: false 
    t.datetime "updated_at", null: false 
    end 

    create_table "sources", force: :cascade do |t| 
    t.string "name" 
    t.datetime "created_at",  null: false 
    t.datetime "updated_at",  null: false 
    t.integer "source_type_id" 
    t.index ["source_type_id"], name: "index_sources_on_source_type_id" 
    end 
end 

這是我想從導入的數據表的架構:

CREATE TABLE quotation_data(
id integer primary key, 
author_name text, 
source_type text, 
source text, 
language text, 
date text, 
title text, 
body text 
); 

我確實在Stackoverflow上發現了一些帖子,但都沒有說明如何將數據從單個表導入分佈在多個模型中的字段。

謝謝!從數據庫

回答

0

我已經導入的數據創建,列出,我已經插入到數據庫中的一切名單。

喜歡:

控制器#顯示

def show 
    @quotes = Quote.all 
end 

意見#顯示

<ul> 
    <% @quotes.each do |quote| %> 
     <li> 
     <%= link_to quotes.title, edit_quotes_path(quote) %> 
     </li> 
    <% end %> 
    </ul> 

這將幫助你查看什麼是數據庫,還可以編輯它。

相關問題