現在ecサイトを作成しており商品のデータをseed_fuでデータベースに入れました。
一番下にあるやつがそうです
この九つの箱にseed_fuで作ったデータを入れる場合どのようにすればいいでしょうか。
分かるかたがいれば教えていただけると嬉しいでお願いします。
ここに該当するview,controller、migrationを載せときます。モデルはまだ何も記述はしていません。
view
.Header-part .Icons .Icons__icon .Icons__icon--user = link_to "#" do = icon('fas', 'user') .Icons__icon .Icons__icon--cart = link_to "#" do = icon('fas', 'cart-plus') .Icons__icon .Icons__icon--heart = icon('fas', 'heart') .Header-part__contents .Header-part__contents__top .Header-part__contents__top_text %h1.Header-part__contents__top__icon = link_to "#", class: 'Header__contents__top__icon__logo' do = image_tag "rental2.png", alt: "logo", width: '120', class: 'Header__contents__top__icon__logo__img' .Header-part__contents__top__search %form.Header-part__contents__top__search__form %input.Header-part__contents__top__search__form__box{"placeholder": "キーワードから探す", "type": "text"} %button.Header-part__contents__top__search__form__btn = image_tag 'icon-search1.png', class: "Header-part__contents__top__search__form__btn__icon-image" .clothes__product %h2.clothes__product__title men's .clothes__product--lists .clothes__product--lists__list = link_to "#",class: "image_tag" do .clothes__product__images = image_tag "rental.png", class: "clothes__product__images" .clothes__product--lists__list__body %h3.clothes__product--name テスト %ul.clothes__product__details__menu %li 10000円 (税込) %li %i.fa.fa-star.likeIcon 1 .clothes__product--lists__list = link_to "#" ,class: "image_tag" do .clothes__product__images = image_tag "rental.png", class: "clothes__product__images" .clothes__product--lists__list__body %h3.clothes__product--name テスト %ul.clothes__product__details__menu %li 10000円 (税込) %li %i.fa.fa-star.likeIcon 1 .clothes__product--lists__list = link_to "#" ,class: "image_tag" do .clothes__product__images = image_tag "rental.png", class: "clothes__product__images" .clothes__product--lists__list__body %h3.clothes__product--name テスト %ul.clothes__product__details__menu %li 10000円 (税込) %li %i.fa.fa-star.likeIcon 1 .clothes__product--lists .clothes__product--lists__list = link_to "#" ,class: "image_tag" do .clothes__product__images = image_tag "rental.png", class: "clothes__product__images" .clothes__product--lists__list__body %h3.clothes__product--name テスト %ul.clothes__product__details__menu %li 10000円 (税込) %li %i.fa.fa-star.likeIcon 1 .clothes__product--lists__list = link_to "#" ,class: "image_tag" do .clothes__product__images = image_tag "rental.png", class: "clothes__product__images" .clothes__product--lists__list__body %h3.clothes__product--name テスト %ul.clothes__product__details__menu %li 10000円 (税込) %li %i.fa.fa-star.likeIcon 1 .clothes__product--lists__list = link_to "#" ,class: "image_tag" do .clothes__product__images = image_tag "rental.png", class: "clothes__product__images" .clothes__product--lists__list__body %h3.clothes__product--name テスト %ul.clothes__product__details__menu %li 10000円 (税込) %li %i.fa.fa-star.likeIcon 1 .clothes__product--lists .clothes__product--lists__list = link_to "#" ,class: "image_tag" do .clothes__product__images = image_tag "rental.png", class: "clothes__product__images" .clothes__product--lists__list__body %h3.clothes__product--name テスト %ul.clothes__product__details__menu %li 10000円 (税込) %li %i.fa.fa-star.likeIcon 1 .clothes__product--lists__list = link_to "#" ,class: "image_tag" do .clothes__product__images = image_tag "rental.png", class: "clothes__product__images" .clothes__product--lists__list__body %h3.clothes__product--name テスト %ul.clothes__product__details__menu %li 10000円 (税込) %li %i.fa.fa-star.likeIcon 1 .clothes__product--lists__list = link_to "#" ,class: "image_tag" do .clothes__product__images = image_tag "rental.png", class: "clothes__product__images" .clothes__product--lists__list__body %h3.clothes__product--name テスト %ul.clothes__product__details__menu %li 10000円 (税込) %li %i.fa.fa-star.likeIcon 1
controller
class MensController < ApplicationController def index @item = Item.all end end
マイグレーション
class CreateItems < ActiveRecord::Migration[6.0] def change create_table :items do |t| t.string :name t.string :item_id, null: false t.timestamps end add_index :items, :item_id, unique: true end end