Module: Faalis::Dashboard::Sections::ResourceCreate::ClassMethods

Defined in:
lib/faalis/dashboard/sections/resource_create.rb

Overview

The actual DSL for index ages

Instance Method Summary collapse

Instance Method Details

#form_fields {|form| ... } ⇒ Object

Yields:

  • (form)

251
252
253
254
255
256
257
258
259
260
# File 'lib/faalis/dashboard/sections/resource_create.rb', line 251

def form_fields
  form = ::Faalis::Dashboard::FormFieldsProperties.new
  yield form

  define_method(:_form_fields) do
    form
  end

  private :_form_fields
end

#in_form(&block) ⇒ Object

To specify any property and action for `form` section both new and edit You must use `in_form` class method with block of properties. For example:

class ExamplesController < Dashboard::Application
  in_form do
    attributes :name, :description
    action_button :close, dashboard_example_close_path
  end
end

216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'lib/faalis/dashboard/sections/resource_create.rb', line 216

def in_form(&block)
  model = model_class
  form_props = Faalis::Dashboard::DSL::Create.new(model)

  unless block_given?
    fail ArgumentError, "You have to provide a block for 'in_form'"
  end


  define_method(:form_properties) do
    unless defined? @__form_props__
      instance_exec(form_props, &block)
      @__form_props__ = form_props
    end
    return @__form_props__
  end

  private :form_properties
end

#new_form_fields(*fields, **options) ⇒ Object

User can provides the fields that he/she wants to be shown in the form for resource creation page. for example:

class Dashboard::PostsController < Dashboard::ApplicationController

new_form_fields :title, created_at

end


243
244
245
246
247
248
249
# File 'lib/faalis/dashboard/sections/resource_create.rb', line 243

def new_form_fields(*fields, **options)
  define_method(:_new_form_fields) do
    fields.map(&:to_sym)
  end

  private :_new_form_fields
end