Module: Locomotive::ContentEntriesHelper

Defined in:
app/helpers/locomotive/content_entries_helper.rb

Instance Method Summary collapse

Instance Method Details

#options_for_belongs_to_custom_field(class_name) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'app/helpers/locomotive/content_entries_helper.rb', line 30

def options_for_belongs_to_custom_field(class_name)
  content_type = Locomotive::ContentType.class_name_to_content_type(class_name, current_site)

  if content_type
    content_type.ordered_entries.map { |entry| [(content_type, entry), entry._id] }
  else
    [] # unknown content type
  end
end

#push_has_many_form(field) ⇒ Object

Keep track of the form used to create / edit content entries from a has_many custom field. Because of formtastic which does not work with embedded forms, we have to render them once we are done with our main form.

Parameters:

  • field (Hash)

    The field describing the relationship



11
12
13
# File 'app/helpers/locomotive/content_entries_helper.rb', line 11

def push_has_many_form(field)
  (@has_many_forms ||= []) << field
end

#render_has_many_formsString

Render all the forms used to create / edit content entries from a has_many custom field. Because of formtastic which does not work with embedded forms, we have to render them once we are done with our main form.

Returns:



22
23
24
25
26
27
28
# File 'app/helpers/locomotive/content_entries_helper.rb', line 22

def render_has_many_forms
  return unless @has_many_forms

  @has_many_forms.map do |field|
    render 'locomotive/custom_fields/types/has_many_form', field: field
  end.join("\n").html_safe
end