Sha256: e0c402c22e6df45a777ec9cda19aa4b8c28af3eea8a65ce80e1a62952705a648

Contents?: true

Size: 1.59 KB

Versions: 1

Compression:

Stored size: 1.59 KB

Contents

class DictionariesController < ApplicationController
  before_action :set_dictionary, only: [:show, :edit, :update, :destroy]

  def index
    @dictionaries = Dictionary.where(resource_type: params[:resource_type], resource_id: params[:resource_id]).page(params[:page]).per(50)
  end

  def show
  end

  def new
    @dictionary = Dictionary.new(resource_type: params[:resource_type], resource_id: params[:resource_id])
  end

  def edit
  end

  def create
    @dictionary = Dictionary.new(dictionary_params)

    respond_to do |format|
      if @dictionary.save
        format.html { redirect_to dictionaries_url(resource_type: @dictionary.resource_type, resource_id: @dictionary.resource_id), notice: '添加成功' }
      else
        format.html { render :new }
      end
    end
  end

  def update
    respond_to do |format|
      if @dictionary.update(dictionary_params)
        format.html { redirect_to dictionaries_url(resource_type: @dictionary.resource_type, resource_id: @dictionary.resource_id), notice: '修改成功' }
      else
        format.html { render :edit }
      end
    end
  end

  def destroy
    url = dictionaries_url(resource_type: @dictionary.resource_type, resource_id: @dictionary.resource_id)
    @dictionary.destroy
    respond_to do |format|
      format.html { redirect_to url, notice: '删除成功' }
    end
  end

  private
    def set_dictionary
      @dictionary = Dictionary.find(params[:id])
    end

    def dictionary_params
      params.require(:dictionary).permit(:resource_type, :resource_id, :key, :value)
    end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
admin-sys-1.1.0 plugins/report/app/controllers/dictionaries_controller.rb