Sha256: 30851c6864145dc134e1e63209fe40bdfde0aa1949f7fd923667d168c95fdcd7
Contents?: true
Size: 1.8 KB
Versions: 1
Compression:
Stored size: 1.8 KB
Contents
module ConstructorPages class FieldsController < ConstructorCore::ApplicationController include TheSortableTreeController::Rebuild include TheSortableTreeController::ExpandNode before_action :set_field, only: [:edit, :update, :destroy] def new @field = Field.new template_id: params[:template_id] end def edit end def create @field = Field.new field_params if @field.save redirect_to edit_template_path(@field.template), notice: t(:field_success_added, name: @field.name) else render :new end end def update unless @field.type_value == params[:field][:type_value] @field.type_class.where(field_id: @field.id).each do |field| _field = "constructor_pages/types/#{params[:field][:type_value]}_type".classify.constantize.new(field_id: @field.id, page_id: field.page_id) unless [@field.type_value, params[:field][:type_value]].include?('image') && (@field.type_value == 'string' && field.value.strip == '') _field.value = field.value end _field.save field.destroy end end if @field.update field_params redirect_to edit_template_path(@field.template.id), notice: t(:field_success_updated, name: @field.name) else render :edit end end def destroy @field.destroy redirect_to edit_template_url(@field.template), notice: t(:field_success_removed, name: @field.name) end def sortable_model; Field end def sortable_collection; ConstructorPages::Field end private def set_field @field = Field.find params[:id] end def field_params params.require(:field).permit( :name, :code_name, :template_id, :type_value ) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
constructor-pages-1.0.0beta2 | app/controllers/constructor_pages/fields_controller.rb |