Today we created a Shopping List application. The source code is available here: https://github.com/ga-chicago/Rails_Shopping_List
def new
# create a new model
@product = Product.new
end
<h1>Add To List</h1>
<h3>New Product</h3>
<%= form_for @product, url: {action: 'create'} do |f| %>
<%= f.text_field :name %>
<%= f.text_field :quantity %>
<%= f.submit 'Add Item' %>
<% end %>
def create
# POST request
# save that model
@product = Product.create(
:name => params[:product][:name],
:quantity => params[:product][:quantity].to_i
)
end
def delete
# find the model
# delete it
@product = Product.find(params[:product][:id].to_i).destroy
end