89 lines
2.3 KiB
Ruby
89 lines
2.3 KiB
Ruby
# encoding=utf-8
|
|
class MainCategoriesController < ApplicationController
|
|
# GET /main_categories
|
|
# GET /main_categories.json
|
|
layout 'admin'
|
|
before_filter :require_admin
|
|
def index
|
|
@main_categories = MainCategory.all
|
|
|
|
respond_to do |format|
|
|
format.html # index.html.erb
|
|
format.json { render json: @main_categories }
|
|
end
|
|
end
|
|
|
|
# GET /main_categories/1
|
|
# GET /main_categories/1.json
|
|
def show
|
|
@main_category = MainCategory.find(params[:id])
|
|
|
|
respond_to do |format|
|
|
format.html # show.html.erb
|
|
format.json { render json: @main_category }
|
|
end
|
|
end
|
|
|
|
# GET /main_categories/new
|
|
# GET /main_categories/new.json
|
|
def new
|
|
@main_category = MainCategory.new
|
|
|
|
respond_to do |format|
|
|
format.html # new.html.erb
|
|
format.js
|
|
format.json { render json: @main_category }
|
|
end
|
|
end
|
|
|
|
# GET /main_categories/1/edit
|
|
def edit
|
|
@main_category = MainCategory.find(params[:id])
|
|
end
|
|
|
|
# POST /main_categories
|
|
# POST /main_categories.json
|
|
def create
|
|
@main_category = MainCategory.new(params[:main_category])
|
|
|
|
respond_to do |format|
|
|
if @main_category.save
|
|
format.html { redirect_to main_categories_path, notice: '主类别创建成功' }
|
|
format.js
|
|
format.json { render json: @main_category, status: :created, location: @main_category }
|
|
else
|
|
format.html { render action: "new" }
|
|
format.json { render json: @main_category.errors, status: :unprocessable_entity }
|
|
end
|
|
end
|
|
end
|
|
|
|
# PUT /main_categories/1
|
|
# PUT /main_categories/1.json
|
|
def update
|
|
@main_category = MainCategory.find(params[:id])
|
|
|
|
respond_to do |format|
|
|
if @main_category.update_attributes(params[:main_category])
|
|
format.html { redirect_to @main_category, notice: '修改数据主类别成功' }
|
|
format.json { head :no_content }
|
|
else
|
|
format.html { render action: "edit" }
|
|
format.json { render json: @main_category.errors, status: :unprocessable_entity }
|
|
end
|
|
end
|
|
end
|
|
|
|
# DELETE /main_categories/1
|
|
# DELETE /main_categories/1.json
|
|
def destroy
|
|
@main_category = MainCategory.find(params[:id])
|
|
@main_category.destroy
|
|
|
|
respond_to do |format|
|
|
format.html { redirect_to main_categories_url }
|
|
format.json { head :no_content }
|
|
end
|
|
end
|
|
end
|