2016-12-01 8 views
0

I持って私のレールのアプリで次のスキーマ:データベース内のテーブルからレールモデルにデータをインポートする方法

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でいくつかの投稿を見つけましたが、1つのテーブルから複数のモデルに分散したフィールドにデータをインポートする方法については説明していません。

ありがとうございます!

答えて

0

私はデータベースからデータをインポートしましたデータベースに挿入したものすべてをリストするリストを作成します。

のような:

の下では、コントローラ#が

def show 
    @quotes = Quote.all 
end 

ビュー#は

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

を示した。これは、データベース上にあるものを表示しても、それを編集するお手伝いをします示して。

関連する問題