Sha256: 87c1eb9a9f2c39550cf547c8abf86864b2bc0b183610ebc9b7e6858d06bd6357
Contents?: true
Size: 1.76 KB
Versions: 18
Compression:
Stored size: 1.76 KB
Contents
require_dependency "push_type/admin_controller" module PushType class TaxonomyTermsController < AdminController before_filter :build_term, only: :create before_filter :load_term, only: [:update, :destroy, :position] def create respond_to do |format| format.json do if @term.save render json: { term: @term.as_json }, status: :created else render json: { errors: @term.errors }, status: :unprocessable_entity end end end end def update respond_to do |format| format.json do if @term.update_attributes taxonomy_params head :ok else render json: { errors: @term.errors }, status: :unprocessable_entity end end end end def destroy respond_to do |format| format.json do @term.destroy head :ok end end end def position respond_to do |format| format.json do reorder_term head :ok end end end private def taxonomy @taxonomy ||= PushType::Taxonomy.descendants.find { |t| t.name.underscore == params[:taxonomy_id] } end def build_term @term = taxonomy.new taxonomy_params end def load_term @term = taxonomy.find params[:id] end def taxonomy_params params.fetch(taxonomy.name.underscore.to_sym, {}).permit(:id, :title, :slug) end def reorder_term if params[:prev] taxonomy.find(params[:prev]).append_sibling(@term) elsif params[:next] taxonomy.find(params[:next]).prepend_sibling(@term) elsif params[:parent] taxonomy.find(params[:parent]).append_child(@term) end end end end
Version data entries
18 entries across 18 versions & 1 rubygems