Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chadyeh 交第一週作業 #311

Open
wants to merge 18 commits into
base: store-v1
Choose a base branch
from
Prev Previous commit
Next Next commit
add products edit function
  • Loading branch information
Chad Yeh authored and Chad Yeh committed Mar 5, 2016
commit 769e6509ee40b1f359afd3507ce97af4d0b96b97
16 changes: 15 additions & 1 deletion app/controllers/admin/products_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Admin::ProductsController < ApplicationController
before_action :authenticate_user!
before_action :admin_required

def index
@products = Product.all
end
Expand All @@ -20,6 +20,20 @@ def create
end
end

def edit
@product = Product.find(params[:id])
end

def update
@product = Product.find(params[:id])

if @product.update(product_params)
redirect_to admin_products_path
else
render :edit
end
end

private

def product_params
Expand Down
23 changes: 23 additions & 0 deletions app/views/admin/products/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<h2> 新增產品 </h2>

<%= simple_form_for [:admin, @product] do |f| %>

<div class="group">
<%= f.input :title %>
</div>

<div class="group">
<%= f.input :description %>
</div>

<div class="group">
<%= f.input :quantity %>
</div>

<div class="group">
<%= f.input :price %>
</div>

<%= f.submit "Submit", data: { disable_with: "Submitting..." } %>

<% end %>