Sha256: 2fd9a094dbdc4c342e793ec97718a06e32e2a832bdf60170b508f9a8be69b13b

Contents?: true

Size: 767 Bytes

Versions: 9

Compression:

Stored size: 767 Bytes

Contents

module <%= cls_classname %>SetupHelper
  def setup_<%= cls_underscore %>(obj)
    <% nested_belongs_to_classes.each do |cls_name| -%>
    obj.build_<%= cls_name %> if obj.<%= cls_name %>.blank?
    <% end -%>
    <% nested_has_many_classes.each do |cls_name| -%>
    obj.<%= cls_name %>.build if obj.<%= cls_name %>.empty?
    <% end -%>
    return obj
  end

<% if options.select_boxes? -%>
  def build_select_list(assoc, options={})
    name  = options[:name]  || "name"
    scope = options[:scope] || "all"
    begin
      # name and id associations
      assoc.to_s.classify.constantize.send(scope).map{|a| [a.send(name), a.id]}
    rescue
      # use id for text and value
      assoc.to_s.classify.constantize.send(scope).map(&:id)
    end
  end
<% end -%>
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
formgen-0.4.1 lib/generators/skizmo/form/templates/setup_helper.rb
formgen-0.4.0 lib/generators/skizmo/form/templates/setup_helper.rb
formgen-0.3.4 lib/generators/skizmo/form/templates/setup_helper.rb
formgen-0.3.3 lib/generators/skizmo/form/templates/setup_helper.rb
formgen-0.3.2 lib/generators/skizmo/form/templates/setup_helper.rb
formgen-0.3.1 lib/generators/skizmo/form/templates/setup_helper.rb
formgen-0.3.0 lib/generators/skizmo/form/templates/setup_helper.rb
formgen-0.2.1 lib/generators/skizmo/form/templates/setup_helper.rb
formgen-0.2.0 lib/generators/skizmo/form/templates/setup_helper.rb