我想知道如何在使用提交按钮后立即在表格下方存储该表格的数据结果。我也很难将值实际存储在我的Postgresql数据库中。
这是我的html.erb中的表单
<%= form_for @order, as: :order, url: root_path, html: { class: "new_order", id: "new_order" } do |f| %>
<div class="field">
Drink: <%= f.select :drink, ['Coffee', 'Orange Juice', 'Tea']%><br />
</div>
<div class="field">
Coffee Type: <%= f.select :drink, ['Espresso', 'Cappuccino', 'Filter', 'Greek', 'Frappe', 'Latte']%><br />
</div>
<div class="field">
Sugar Amount: <%= f.select :sugar, ((0..5).map {|i| [i,i] } << ["None",nil]) %><br />
</div>
<div class="field">
Milk Amount: <%= f.select :milk, ((0..5).map {|i| [i,i] } << ["None",nil]) %><br />
</div>
<%= f.submit %>
<% end -%>
这是我的订单管理员
class OrderController < ApplicationController
def new
@order = Order.new
end
def create
@order = Order.new(params[:id])
if @order.save
redirect_to root_path
end
end
def index
@orders = Order.all
end
end