Sha256: 92b44e9b5cefeaf5eca8401c752a94f1ddcba8b833bb47221180237973843193
Contents?: true
Size: 1.67 KB
Versions: 16
Compression:
Stored size: 1.67 KB
Contents
module Fae class StaticPagesController < ApplicationController before_action :set_class_variables before_action :set_item, only: [:edit, :update, :destroy] helper FormHelper def index raise 'Missing blocks method inside StaticPages\' child controller' unless fae_pages @items = fae_pages.map { |b| b.instance } end def edit build_assocs params[:static_page] = true render params[:slug] end def update if @item.update(item_params) redirect_to @index_path, notice: t('fae.save_notice') else build_assocs render template: "#{fae.root_path.gsub('/', '')}/content_blocks/#{params[:slug]}", error: t('fae.save_error') end end private # Use callbacks to share common setup or constraints between actions. def set_item @item = "#{params[:slug]}_page".classify.constantize.instance end # set up variables so that fae partial forms work def set_class_variables(class_name = nil) @klass_name = class_name || 'Pages' @klass_singular = @klass_name.singularize @klass_humanized = @klass_singular.humanize @index_path = "#{Rails.application.routes.url_helpers.fae_path}/#{@klass_name.underscore.downcase}" end # Only allow a trusted parameter "white list" through. def item_params model = @item.class.name.split('::').last.underscore params.require(:"#{model}").permit! end def build_assocs @item.class.reflect_on_all_associations.each do |assoc| @item.send(:"create_#{assoc.name}", attached_as: assoc.name.to_s) if assoc.macro == :has_one && @item.send(:"#{assoc.name}").blank? end end end end
Version data entries
16 entries across 16 versions & 2 rubygems