Sha256: a440a77b819164e46510ccbf8bc1075a7a534ef2141531ec00bf09f04d645e45

Contents?: true

Size: 1.39 KB

Versions: 20

Compression:

Stored size: 1.39 KB

Contents

module ActiveAdmin
  module Views
    module Pages

      class Form < Base

        def title
          assigns[:page_title] || I18n.t("active_admin.#{normalized_action}_model",
                                         model: active_admin_config.resource_label)
        end

        def form_presenter
          active_admin_config.get_page_presenter(:form) || default_form_config
        end

        def main_content
          options = default_form_options.merge form_presenter.options

          if options[:partial]
            render options[:partial]
          else
            active_admin_form_for resource, options, &form_presenter.block
          end
        end

        private

        def default_form_options
          {
            url: default_form_path,
            as: active_admin_config.param_key
          }
        end

        def default_form_path
          resource.persisted? ? resource_path(resource) : collection_path
        end

        def default_form_config
          ActiveAdmin::PagePresenter.new do |f|
            f.semantic_errors # show errors on :base by default
            f.inputs
            f.actions
          end
        end

        def normalized_action
          case params[:action]
          when "create"
            "new"
          when "update"
            "edit"
          else
            params[:action]
          end
        end
      end

    end
  end
end

Version data entries

20 entries across 20 versions & 3 rubygems

Version Path
activeadmin_addons-1.1.2 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-a5a53c3f2b8f/lib/active_admin/views/pages/form.rb
activeadmin_addons-1.1.1 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/lib/active_admin/views/pages/form.rb
yousty-activeadmin-1.0.17.pre lib/active_admin/views/pages/form.rb
yousty-activeadmin-1.0.16.pre lib/active_admin/views/pages/form.rb
activeadmin_addons-1.1.0 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/lib/active_admin/views/pages/form.rb
activeadmin_addons-1.0.1 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/lib/active_admin/views/pages/form.rb
activeadmin_addons-1.0.0 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/lib/active_admin/views/pages/form.rb
yousty-activeadmin-1.0.15.pre lib/active_admin/views/pages/form.rb
yousty-activeadmin-1.0.14.pre lib/active_admin/views/pages/form.rb
yousty-activeadmin-1.0.13.pre lib/active_admin/views/pages/form.rb
yousty-activeadmin-1.0.12.pre lib/active_admin/views/pages/form.rb
yousty-activeadmin-1.0.11.pre lib/active_admin/views/pages/form.rb
yousty-activeadmin-1.0.10.pre lib/active_admin/views/pages/form.rb
yousty-activeadmin-1.0.9.pre lib/active_admin/views/pages/form.rb
yousty-activeadmin-1.0.8.pre lib/active_admin/views/pages/form.rb
activeadmin-1.0.0.pre2 lib/active_admin/views/pages/form.rb
activeadmin-1.0.0.pre1 lib/active_admin/views/pages/form.rb
yousty-activeadmin-1.0.7.pre lib/active_admin/views/pages/form.rb
yousty-activeadmin-1.0.6.pre lib/active_admin/views/pages/form.rb
yousty-activeadmin-1.0.5.pre lib/active_admin/views/pages/form.rb