Admin category edit/update action

This commit is contained in:
Rei
2014-02-08 19:02:21 +08:00
parent db9ef91466
commit ea322249dc
4 changed files with 49 additions and 1 deletions

View File

@@ -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

View 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'

View File

@@ -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

View File

@@ -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