Sha256: 27d2dab429b50ff80dddd4d4273a3034918e0fe3a5cd38c3287acb2937e7a035

Contents?: true

Size: 1.33 KB

Versions: 18

Compression:

Stored size: 1.33 KB

Contents

module RailsCoreExtensions
  module HasManyExtensions
    module Tags
      def hm_check_box(object_name, method, options = {})
        object = options.delete(:object)
        parent = options.delete(:parent) || instance_variable_get(object_name)
        objects = options.delete(:objects) || parent.send(method)
        check_box_tag("#{object_name}[#{method}][]", object, objects.include?(object), options.merge(:id => "#{object_name}_#{method}"))
      end

      def hm_empty_array(object_name, method)
        hidden_field_tag "#{object_name}[#{method}][]"
      end
    end

    module FormBuilder
      def hm_empty_array(method)
        @habtm_fields ||= {}
        @habtm_fields[method] = @object.send(method)
        @template.hm_empty_array(@object_name, method)
      end

      def hm_check_box(method, object, options = {})
        empty = (hm_empty_array(method) unless @habtm_fields && @habtm_fields[method])
        (empty || '').html_safe + @template.hm_check_box(@object_name, method, options.merge(:object => object, :parent => @object, :objects => @habtm_fields[method]))
      end
    end
  end
end

ActionView::Base.send(:include, RailsCoreExtensions::HasManyExtensions::Tags) if defined?(ActionView::Base)
ActionView::Helpers::FormBuilder.send(:include, RailsCoreExtensions::HasManyExtensions::FormBuilder) if defined?(ActionView::Base)

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
rails_core_extensions-0.12.0 lib/rails_core_extensions/action_view_has_many_extensions.rb
rails_core_extensions-0.11.3 lib/rails_core_extensions/action_view_has_many_extensions.rb
rails_core_extensions-0.11.2 lib/rails_core_extensions/action_view_has_many_extensions.rb
rails_core_extensions-0.11.1 lib/rails_core_extensions/action_view_has_many_extensions.rb
rails_core_extensions-0.11.0.beta.11 lib/rails_core_extensions/action_view_has_many_extensions.rb
rails_core_extensions-0.10.0 lib/rails_core_extensions/action_view_has_many_extensions.rb
rails_core_extensions-0.9.0 lib/rails_core_extensions/action_view_has_many_extensions.rb
rails_core_extensions-0.8.0 lib/rails_core_extensions/action_view_has_many_extensions.rb
rails_core_extensions-0.7.1 lib/rails_core_extensions/action_view_has_many_extensions.rb
rails_core_extensions-0.7.0 lib/rails_core_extensions/action_view_has_many_extensions.rb
rails_core_extensions-0.6.1 lib/rails_core_extensions/action_view_has_many_extensions.rb
rails_core_extensions-0.6.0 lib/rails_core_extensions/action_view_has_many_extensions.rb
rails_core_extensions-0.4.0 lib/rails_core_extensions/action_view_has_many_extensions.rb
rails_core_extensions-0.3.0 lib/rails_core_extensions/action_view_has_many_extensions.rb
rails_core_extensions-0.2.0 lib/rails_core_extensions/action_view_has_many_extensions.rb
rails_core_extensions-0.1.1 lib/rails_core_extensions/action_view_has_many_extensions.rb
rails_core_extensions-0.1.0 lib/rails_core_extensions/action_view_has_many_extensions.rb
rails_core_extensions-0.0.1 lib/rails_core_extensions/action_view_has_many_extensions.rb