Sha256: c3ce20332507a4e9636ec382d5679ed9f3a35ebae7aeef3f91897ba7e3279c46

Contents?: true

Size: 1.27 KB

Versions: 2

Compression:

Stored size: 1.27 KB

Contents

require 'property_sets/form_builder_proxy'

module ActionView
  module Helpers
    # property_set_check_box(:account, :property_association, :property_key, options)
    def property_set_check_box(model_name, property_set, property, options = {}, checked_value = "1", unchecked_value = "0")
      the_model = @template.instance_variable_get("@#{model_name}")

      throw "No @#{model_name} in scope" if the_model.nil?
      throw "The property_set_check_box only works on models with property set #{property_set}" unless the_model.respond_to?(property_set)

      options[:checked] = the_model.send(property).send("#{method}?")
      options[:id]    ||= "#{model_name}_property_sets_#{property_set}_#{method}"
      options[:name]    = "#{model_name}[property_sets][#{property_set}][#{method}]"
      @template.check_box(model_name, "property_sets_#{property_set}_#{method}", options, checked_value, unchecked_value)
    end
  end

  class FormBuilder
    def property_set(identifier)
      PropertySets::FormBuilderProxy.new(identifier, self)
    end

    def property_set_check_box(property_set, property, options, checked_value, unchecked_value)
      @template.property_set_check_box(@object_name, property_set, property, objectify_options(options), checked_value, unchecked_value)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
property_sets-0.1.0 lib/property_sets/property_set_helper.rb
property_sets-0.0.12 lib/property_sets/property_set_helper.rb