Sha256: 60d52854582331ffdb64a569a5a6e5be5a98a78ed7be066eea649dac3ee96de4

Contents?: true

Size: 1.19 KB

Versions: 12

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

module PagesCore
  module Admin
    class FormBuilder < PagesCore::FormBuilder
      include DynamicImage::Helper
      include PagesCore::Admin::LocalizedFormBuilder

      def rich_text_area(attr, options = {})
        @template.rich_text_area_tag(
          "#{object_name}[#{attr}]",
          object.send(attr),
          localized_form_field_options(attr).merge(options)
        )
      end

      def image_uploader(attr, options = {})
        @template.image_uploader_tag(
          "#{object_name}[#{foreign_key(attr)}]",
          object.send(attr),
          options
        )
      end

      def labelled_rich_text_area(attribute, label_text = nil, options = {})
        labelled_field(attribute, label_text, options) do |opts|
          rich_text_area(attribute, opts)
        end
      end

      def labelled_image_uploader(attribute, label_text = nil, options = {})
        labelled_field(attribute, label_text, options) do |opts|
          image_uploader(attribute, opts)
        end
      end

      private

      def foreign_key(attr)
        object.class.reflections[attr.to_s].options[:foreign_key] ||
          "#{attr}_id".to_sym
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
pages_core-3.12.7 app/helpers/pages_core/admin/form_builder.rb
pages_core-3.12.6 app/helpers/pages_core/admin/form_builder.rb
pages_core-3.12.5 app/helpers/pages_core/admin/form_builder.rb
pages_core-3.12.4 app/helpers/pages_core/admin/form_builder.rb
pages_core-3.12.3 app/helpers/pages_core/admin/form_builder.rb
pages_core-3.12.2 app/helpers/pages_core/admin/form_builder.rb
pages_core-3.12.1 app/helpers/pages_core/admin/form_builder.rb
pages_core-3.12.0 app/helpers/pages_core/admin/form_builder.rb
pages_core-3.11.3 app/helpers/pages_core/admin/form_builder.rb
pages_core-3.11.2 app/helpers/pages_core/admin/form_builder.rb
pages_core-3.11.1 app/helpers/pages_core/admin/form_builder.rb
pages_core-3.11.0 app/helpers/pages_core/admin/form_builder.rb