Я создал простой интернет-магазин. Я использую Rails admin для загрузки каждого продукта с основной информацией, такой как: название,: фото,: описание и: цена. Каждый выбранный продукт добавляется в корзину, а затем в заказ.
Что я хотел бы сделать, это когда пользователь выбирает продукт; То, что они могут выбрать свой выбранный размер и цвет , в котором они хотят получить продукт. Мне было интересно, как это сделать, поскольку мне потребовался бы ввод от пользователей.
Я попытался создать форму и отобразить ее в продукте, чтобы добавить эти параметры. Кто-нибудь знает о каких-либо других альтернативах?
Я также пытался создать форму Выбрать на моем Продукт / Индекс:
<select name="product[size]" id="product_quantity"><option value="size"></option>
<option selected="selected" value="1">XS</option>
<option value="2">S</option>
<option value="3">M</option>
<option value="4">L</option>
<option value="5">XL</option></select>
Но я не могу отобразить пользовательский ввод для моего заказа.
Я также читал о создании вариантов продукта , но я не знаю, как это реализовать ...
Это мой index.html.erb Просмотров продукта
<section class="product-list">
<div class="container">
<% @product.each do |product| %>
<div class="row">
<div class="col-md-12">
<div class="product">
<div class="row">
<div class="col-md-6 col-xs-12">
<div class="thumbnail">
<%= cl_image_tag product.photo %>
</div>
</div>
<div class="col-md-5 col-md-offset-1">
<div class="product-details">
<h2 class="product-title"> <a href=""><%= link_to product.title, product %></h2>
<p class="product-price"><%= number_to_currency product.price %></p>
<p><%= product.description %></p>
<%= button_to product_items_path(product_id: product.id), class: 'btn btn-default' do %>
<i class="fa fa-shopping-cart"></i> Add to cart
<% end %>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- /.row -->
<% end %>
</div>
</section>
Моя схема:
create_table "active_admin_comments", force: :cascade do |t|
t.string "namespace"
t.text "body"
t.string "resource_type"
t.bigint "resource_id"
t.string "author_type"
t.bigint "author_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["author_type", "author_id"], name: "index_active_admin_comments_on_author_type_and_author_id"
t.index ["namespace"], name: "index_active_admin_comments_on_namespace"
t.index ["resource_type", "resource_id"], name: "index_active_admin_comments_on_resource_type_and_resource_id"
end
create_table "admin_users", force: :cascade do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["email"], name: "index_admin_users_on_email", unique: true
t.index ["reset_password_token"], name: "index_admin_users_on_reset_password_token", unique: true
end
create_table "carts", force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "contacts", force: :cascade do |t|
t.string "name"
t.string "email"
t.text "message"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "orders", force: :cascade do |t|
t.string "name"
t.string "email"
t.text "address"
t.string "city"
t.string "country"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "shipped", default: false
end
create_table "product_items", force: :cascade do |t|
t.bigint "product_id"
t.bigint "cart_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "quantity", default: 1
t.bigint "order_id"
t.index ["cart_id"], name: "index_product_items_on_cart_id"
t.index ["order_id"], name: "index_product_items_on_order_id"
t.index ["product_id"], name: "index_product_items_on_product_id"
end
create_table "products", force: :cascade do |t|
t.string "title"
t.string "photo"
t.text "description"
t.decimal "price"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "size"
t.string "size2"
end
add_foreign_key "product_items", "carts"
add_foreign_key "product_items", "orders"
add_foreign_key "product_items", "products"
end