Sha256: 6855b59168c6aca25e01d183d53a4a57866f699407e2ae47a630d149c5a5515b

Contents?: true

Size: 1.74 KB

Versions: 25

Compression:

Stored size: 1.74 KB

Contents

require 'action_view'
require 'action_view/helpers'

ActionView::Helpers::FormHelper.module_eval do

  def required_label(object_name, method, text = nil, options = {})
    options = {:class => "required"}.merge!(options)

    label(object_name, method, "#{label_humanize_text(object_name, method, text, options)} *", options)
  end


  def label_humanize_text object_name, method, text = nil, options = {}
    if text.blank?
      text = object_name.classify.constantize.respond_to?(:human_attribute_name) ? object_name.classify.constantize.human_attribute_name(method) : method.to_s
    else
      text = text.to_s
    end
    text.humanize
  end

end

ActionView::Helpers::FormBuilder.module_eval do

  def required_label(method, text = nil, options = {})
    @template.required_label(@object_name, method, text, objectify_options(options))
  end

end

ActionView::Helpers::FormTagHelper.module_eval do

  def required_label_tag(name, text = nil, options = {})
    options = {:class => "required"}.merge!(options)
    text ||= "#{name.to_s.humanize} *"

    label_tag(name, text, options)
  end

end


# I18n labels automatically
module ActionView
  module Helpers
    class InstanceTag
      def to_label_tag(text = nil, options = {})
        options = options.stringify_keys
        name_and_id = options.dup
        add_default_name_and_id(name_and_id)
        options.delete("index")
        options["for"] ||= name_and_id["id"]
        if text.blank?
          content = method_name.humanize
          if object.class.respond_to?(:human_attribute_name)
            content = object.class.human_attribute_name(method_name)
          end
        else
          content = text.to_s
        end
        label_tag(name_and_id["id"], content, options)
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 2 rubygems

Version Path
refinerycms-core-1.0.3 lib/refinery/helpers/form_helper.rb
refinerycms-core-1.0.1 lib/refinery/helpers/form_helper.rb
refinerycms-core-1.0.0 lib/refinery/helpers/form_helper.rb
refinerycms-core-0.9.9.22 lib/refinery/helpers/form_helper.rb
refinerycms-core-0.9.9.21 lib/refinery/helpers/form_helper.rb
refinerycms-core-0.9.9.20 lib/refinery/helpers/form_helper.rb
refinerycms-core-0.9.9.19 lib/refinery/helpers/form_helper.rb
refinerycms-core-0.9.9.18 lib/refinery/helpers/form_helper.rb
refinerycms-core-0.9.9.17 lib/refinery/helpers/form_helper.rb
refinerycms-core-0.9.9.16 lib/refinery/helpers/form_helper.rb
refinerycms-core-0.9.9.15 lib/refinery/helpers/form_helper.rb
refinerycms-core-0.9.9.14 lib/refinery/helpers/form_helper.rb
refinerycms-core-0.9.9.13 lib/refinery/helpers/form_helper.rb
refinerycms-core-0.9.9.12 lib/refinery/helpers/form_helper.rb
refinerycms-core-0.9.9.11 lib/refinery/helpers/form_helper.rb
refinerycms-core-0.9.9.10 lib/refinery/helpers/form_helper.rb
refinerycms-core-0.9.9.9 lib/refinery/helpers/form_helper.rb
refinerycms-core-0.9.9.8 lib/refinery/helpers/form_helper.rb
refinerycms-core-0.9.9.7 lib/refinery/helpers/form_helper.rb
refinerycms-core-0.9.9.5 lib/refinery/helpers/form_helper.rb