mirror of
https://github.com/zhigang1992/tsemple.git
synced 2026-04-29 05:05:25 +08:00
Admin category edit/update action
This commit is contained in:
@@ -22,6 +22,17 @@ class Admin::CategoriesController < Admin::ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def update
|
||||
if @category.update_attributes category_params
|
||||
redirect_to admin_category_path(@category)
|
||||
else
|
||||
render :edit
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def category_params
|
||||
|
||||
22
app/views/admin/categories/edit.html.slim
Normal file
22
app/views/admin/categories/edit.html.slim
Normal file
@@ -0,0 +1,22 @@
|
||||
ol.breadcrumb
|
||||
li
|
||||
a href=admin_categories_path Categories
|
||||
li
|
||||
a href=admin_category_path(@category) = @category.name
|
||||
li.active Edit
|
||||
|
||||
.row
|
||||
.col-md-9
|
||||
.panel
|
||||
.panel-body
|
||||
= form_for @category, url: admin_category_path(@category) do |f|
|
||||
.form-group
|
||||
= f.label :name
|
||||
= f.text_field :name, class: 'form-control'
|
||||
.form-group
|
||||
= f.label :slug
|
||||
= f.text_field :slug, class: 'form-control'
|
||||
.form-group
|
||||
= f.label :description
|
||||
= markdown_area f, :description
|
||||
= f.submit 'Save changes', class: 'btn btn-success'
|
||||
@@ -6,7 +6,7 @@ ol.breadcrumb
|
||||
|
||||
.row
|
||||
.col-md-9
|
||||
.panel
|
||||
.panel.panel-campo
|
||||
.panel-body
|
||||
dl
|
||||
dt Name
|
||||
@@ -17,3 +17,7 @@ ol.breadcrumb
|
||||
dd = @category.description
|
||||
dt Topics count
|
||||
dd = @category.topics_count
|
||||
.col-md-3
|
||||
.panel.panel-campo
|
||||
.panel-body
|
||||
a.btn.btn-default.btn-block href=edit_admin_category_path(@category) Edit
|
||||
|
||||
@@ -26,4 +26,15 @@ class Admin::CategoriesControllerTest < ActionController::TestCase
|
||||
post :create, category: attributes_for(:category)
|
||||
end
|
||||
end
|
||||
|
||||
test "should edit category" do
|
||||
get :edit, id: create(:category)
|
||||
assert_response :success, @response.body
|
||||
end
|
||||
|
||||
test "should update category" do
|
||||
category = create(:category)
|
||||
patch :update, id: category, category: { name: 'change' }
|
||||
assert_equal 'change', category.reload.name
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user