完成子类数据;主类数据功能

This commit is contained in:
huang 2018-02-07 16:19:16 +08:00
parent 2bb713c7b9
commit 65e2433592
5 changed files with 17 additions and 9 deletions

View File

@ -13,6 +13,10 @@ class StatisticsController < ApplicationController
end
end
def search
end
# GET /statistics/1
# GET /statistics/1.json
def show

View File

@ -1,5 +1,6 @@
class SubCategoriesController < ApplicationController
layout 'admin'
before_filter :find_main_category, :only => [:new, :edit]
before_filter :require_admin
# GET /sub_categories
# GET /sub_categories.json
@ -27,7 +28,6 @@ class SubCategoriesController < ApplicationController
# GET /sub_categories/new.json
def new
@sub_category = SubCategory.new
@main_categories = MainCategory.all
respond_to do |format|
format.html # new.html.erb
format.json { render json: @sub_category }
@ -46,7 +46,7 @@ class SubCategoriesController < ApplicationController
respond_to do |format|
if @sub_category.save
format.html { redirect_to @sub_category, notice: 'Sub category was successfully created.' }
format.html { redirect_to sub_categories_path, notice: 'Sub category was successfully created.' }
format.json { render json: @sub_category, status: :created, location: @sub_category }
else
format.html { render action: "new" }
@ -62,7 +62,7 @@ class SubCategoriesController < ApplicationController
respond_to do |format|
if @sub_category.update_attributes(params[:sub_category])
format.html { redirect_to @sub_category, notice: 'Sub category was successfully updated.' }
format.html { redirect_to sub_categories_path, notice: 'Sub category was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
@ -82,4 +82,9 @@ class SubCategoriesController < ApplicationController
format.json { head :no_content }
end
end
private
def find_main_category
@main_categories = MainCategory.all
end
end

View File

@ -10,8 +10,8 @@
<% @main_categories.each do |main_category| %>
<tr>
<td><%= main_category.name %></td>
<td><%= format_time main_category.created_at %></td>
<td>
<%#= link_to 'Show', main_category %>
<%= link_to '编辑', edit_main_category_path(main_category) %>
<%= link_to '删除', main_category, method: :delete, data: { confirm: '确定删除这个数据类别吗?' } %>
</td>

View File

@ -1,6 +1,3 @@
<h1>Editing sub_category</h1>
<%= render 'form' %>
<%= link_to 'Show', @sub_category %> |
<%= link_to 'Back', sub_categories_path %>

View File

@ -5,15 +5,17 @@
<tr>
<th>类别名称</th>
<th>主类别名称</th>
<th>创建时间</th>
<th>操作</th>
</tr>
<% @sub_categories.each do |sub_category| %>
<tr>
<td><%= sub_category.name %></td>
<td><%= sub_category.main_category_id %></td>
<td><%= sub_category.main_category.try(:name) %></td>
<td><%= format_time sub_category.created_at %></td>
<td>
<%#= link_to 'Show', sub_category %>
<%= link_to '新建', new_sub_category_path %>
<%= link_to '编辑', edit_sub_category_path(sub_category) %>
<%= link_to '删除', sub_category, method: :delete, data: { confirm: '确认删除这个子类别吗?' } %>
</td>