Class: ActionView::Helpers::InstanceTag

### Home Classes Methods

### In Files

- lib/action_view/helpers/date_helper.rb
- lib/action_view/helpers/form_helper.rb
- lib/action_view/helpers/form_options_helper.rb

### Parent

Object

### Methods

- ::check_box_checked?
- ::new
- ::radio_button_checked?
- ::value
- ::value_before_type_cast
- #retrieve_autoindex
- #retrieve_object
- #to_boolean_select_tag
- #to_check_box_tag
- #to_content_tag
- #to_input_field_tag
- #to_label_tag
- #to_number_field_tag
- #to_radio_button_tag
- #to_text_area_tag
- #value
- #value_before_type_cast

### Included Modules

- ActionView::Helpers::ActiveModelInstanceTag
- ActionView::Helpers::TagHelper
- ActionView::Helpers::FormTagHelper

### Class/Module Index

Quicksearch

- ActionDispatch
- ActionDispatch::Assertions
- ActionDispatch::Assertions::DomAssertions
- ActionDispatch::Assertions::ResponseAssertions
- ActionDispatch::Assertions::RoutingAssertions
- ActionDispatch::Assertions::SelectorAssertions
- ActionDispatch::Assertions::TagAssertions
- ActionDispatch::BestStandardsSupport
- ActionDispatch::BodyProxy
- ActionDispatch::Callbacks
- ActionDispatch::Cookies
- ActionDispatch::Cookies::CookieOverflow
- ActionDispatch::DebugExceptions
- ActionDispatch::ExceptionWrapper
- ActionDispatch::FileHandler
- ActionDispatch::Flash
- ActionDispatch::Flash::FlashHash
- ActionDispatch::Head
- ActionDispatch::Http
- ActionDispatch::Http::Cache
- ActionDispatch::Http::Cache::Request
- ActionDispatch::Http::Cache::Response
- ActionDispatch::Http::FilterParameters
- ActionDispatch::Http::Headers
- ActionDispatch::Http::MimeNegotiation
- ActionDispatch::Http::ParameterFilter
- ActionDispatch::Http::Parameters
- ActionDispatch::Http::URL
- ActionDispatch::Http::Upload
- ActionDispatch::Http::UploadedFile
- ActionDispatch::Integration
- ActionDispatch::Integration::RequestHelpers
- ActionDispatch::Integration::Runner
- ActionDispatch::Integration::Session
- ActionDispatch::IntegrationTest
- ActionDispatch::MiddlewareStack
- ActionDispatch::MiddlewareStack::Middleware
- ActionDispatch::ParamsParser
- ActionDispatch::PerformanceTest
- ActionDispatch::PublicExceptions
- ActionDispatch::RailsEntityStore
- ActionDispatch::RailsMetaStore
- ActionDispatch::Railtie
- ActionDispatch::Reloader
- ActionDispatch::RemoteIp
- ActionDispatch::RemoteIp::GetIp
- ActionDispatch::RemoteIp::IpSpoofAttackError
- ActionDispatch::Request
- ActionDispatch::RequestId
- ActionDispatch::Rescue
- ActionDispatch::Response
- ActionDispatch::Routing
- ActionDispatch::Routing::Mapper
- ActionDispatch::Routing::Mapper::Base
- ActionDispatch::Routing::Mapper::HttpHelpers
- ActionDispatch::Routing::Mapper::Resources
- ActionDispatch::Routing::Mapper::Scoping
- ActionDispatch::Routing::PolymorphicRoutes
- ActionDispatch::Routing::Redirection
- ActionDispatch::Routing::RouteSet
- ActionDispatch::Routing::RouteSet::MountedHelpers
- ActionDispatch::Routing::UrlFor
- ActionDispatch::Session
- ActionDispatch::Session::AbstractStore
- ActionDispatch::Session::CacheStore
- ActionDispatch::Session::Compatibility
- ActionDispatch::Session::CookieStore
- ActionDispatch::Session::DestroyableSession
- ActionDispatch::Session::MemCacheStore
- ActionDispatch::Session::StaleSessionCheck
- ActionDispatch::ShowExceptions
- ActionDispatch::Static
- ActionDispatch::TestProcess
- ActionDispatch::TestRequest
- ActionDispatch::TestResponse
- ActionController
- ActionController::Base
- ActionController::Caching
- ActionController::Caching::Actions
- ActionController::Caching::Actions::ActionCachePath
- ActionController::Caching::Actions::ClassMethods
- ActionController::Caching::ConfigMethods
- ActionController::Caching::Fragments
- ActionController::Caching::Pages
- ActionController::Caching::Pages::ClassMethods
- ActionController::Caching::Sweeping
- ActionController::Compatibility
- ActionController::ConditionalGet
- ActionController::Cookies
- ActionController::DataStreaming
- ActionController::Flash
- ActionController::ForceSSL
- ActionController::ForceSSL::ClassMethods
- ActionController::Head
- ActionController::Helpers
- ActionController::Helpers::ClassMethods
- ActionController::HideActions
- ActionController::HideActions::ClassMethods
- ActionController::HttpAuthentication
- ActionController::HttpAuthentication::Basic
- ActionController::HttpAuthentication::Basic::ControllerMethods
- ActionController::HttpAuthentication::Basic::ControllerMethods::ClassMethods
- ActionController::HttpAuthentication::Digest
- ActionController::HttpAuthentication::Digest::ControllerMethods
- ActionController::HttpAuthentication::Token
- ActionController::HttpAuthentication::Token::ControllerMethods
- ActionController::ImplicitRender
- ActionController::Instrumentation
- ActionController::Instrumentation::ClassMethods
- ActionController::LogSubscriber
- ActionController::Metal
- ActionController::Middleware
- ActionController::Middleware::ActionMiddleware
- ActionController::MimeResponds
- ActionController::MimeResponds::ClassMethods
- ActionController::ParamsWrapper
- ActionController::ParamsWrapper::ClassMethods
- ActionController::RackDelegation
- ActionController::Railtie
- ActionController::Railties
- ActionController::Railties::Paths
- ActionController::RecordIdentifier
- ActionController::Redirecting
- ActionController::Renderers
- ActionController::Renderers::All
- ActionController::Renderers::ClassMethods
- ActionController::Rendering
- ActionController::RequestForgeryProtection
- ActionController::RequestForgeryProtection::ClassMethods
- ActionController::Rescue
- ActionController::Responder
- ActionController::SessionManagement
- ActionController::SessionManagement::ClassMethods
- ActionController::Streaming
- ActionController::TemplateAssertions
- ActionController::TestCase
- ActionController::TestCase::Behavior
- ActionController::TestCase::Behavior::ClassMethods
- ActionController::TestCase::RaiseActionExceptions
- ActionController::TestResponse
- ActionController::Testing
- ActionController::Testing::ClassMethods
- ActionController::UrlFor
- ActionView
- ActionView::Base
- ActionView::Context
- ActionView::FileSystemResolver
- ActionView::FixtureResolver
- ActionView::Helpers
- ActionView::Helpers::ActiveModelHelper
- ActionView::Helpers::ActiveModelInstanceTag
- ActionView::Helpers::AssetPaths
- ActionView::Helpers::AssetTagHelper
- ActionView::Helpers::AssetTagHelper::AssetIncludeTag
- ActionView::Helpers::AssetTagHelper::JavascriptIncludeTag
- ActionView::Helpers::AssetTagHelper::JavascriptTagHelpers
- ActionView::Helpers::AssetTagHelper::JavascriptTagHelpers::ClassMethods
- ActionView::Helpers::AssetTagHelper::StylesheetIncludeTag
- ActionView::Helpers::AssetTagHelper::StylesheetTagHelpers
- ActionView::Helpers::AssetTagHelper::StylesheetTagHelpers::ClassMethods
- ActionView::Helpers::AtomFeedHelper
- ActionView::Helpers::AtomFeedHelper::AtomBuilder
- ActionView::Helpers::AtomFeedHelper::AtomFeedBuilder
- ActionView::Helpers::CacheHelper
- ActionView::Helpers::CaptureHelper
- ActionView::Helpers::CsrfHelper
- ActionView::Helpers::DateHelper
- ActionView::Helpers::DateHelperInstanceTag
- ActionView::Helpers::DebugHelper
- ActionView::Helpers::FormBuilder
- ActionView::Helpers::FormHelper
- ActionView::Helpers::FormOptionsHelper
- ActionView::Helpers::FormTagHelper
- ActionView::Helpers::InstanceTag
- ActionView::Helpers::JavaScriptHelper
- ActionView::Helpers::OutputSafetyHelper
- ActionView::Helpers::RecordTagHelper
- ActionView::Helpers::RenderingHelper
- ActionView::Helpers::SanitizeHelper
- ActionView::Helpers::TagHelper
- ActionView::Helpers::TextHelper
- ActionView::Helpers::TranslationHelper
- ActionView::Helpers::UrlHelper
- ActionView::LogSubscriber
- ActionView::LookupContext
- ActionView::LookupContext::DetailsCache
- ActionView::LookupContext::ViewPaths
- ActionView::NullResolver
- ActionView::PartialRenderer
- ActionView::Railtie
- ActionView::Renderer
- ActionView::Resolver
- ActionView::Resolver::Path
- ActionView::Template
- ActionView::Template::Handlers
- ActionView::Template::Handlers::Builder
- ActionView::Template::Handlers::ERB
- ActionView::Template::Handlers::Erubis
- ActionView::TestCase
- ActionView::TestCase::Behavior
- ActionView::TestCase::Behavior::ClassMethods
- ActionView::TestCase::Behavior::Locals
- ActionView::TestCase::TestController
- AbstractController
- AbstractController::ActionNotFound
- AbstractController::AssetPaths
- AbstractController::Base
- AbstractController::Callbacks
- AbstractController::Callbacks::ClassMethods
- AbstractController::Collector
- AbstractController::DoubleRenderError
- AbstractController::Error
- AbstractController::Helpers
- AbstractController::Helpers::ClassMethods
- AbstractController::Layouts
- AbstractController::Layouts::ClassMethods
- AbstractController::Layouts::ClassMethods::LayoutConditions
- AbstractController::Logger
- AbstractController::Railties
- AbstractController::Railties::RoutesHelpers
- AbstractController::Rendering
- AbstractController::Rendering::ClassMethods
- AbstractController::Translation
- AbstractController::UrlFor
- AbstractController::UrlFor::ClassMethods
- AbstractController::ViewPaths
- AbstractController::ViewPaths::ClassMethods
- Sprockets
- Sprockets::Bootstrap
- Sprockets::Compressors
- Sprockets::Helpers
- Sprockets::Helpers::IsolatedHelper
- Sprockets::Helpers::RailsHelper
- Sprockets::Helpers::RailsHelper::AssetPaths
- Sprockets::Helpers::RailsHelper::AssetPaths::AssetNotPrecompiledError
- Sprockets::Railtie
- Sprockets::StaticCompiler
- HTML
- HTML::FullSanitizer
- HTML::LinkSanitizer
- HTML::Sanitizer
- HTML::Selector
- HTML::Tag
- HTML::WhiteListSanitizer
- Mime
- Mime::Mimes
- Mime::Type
- ActionPack
- Object
- Rack

No matching classes.

# ActionView::Helpers::InstanceTag

### Constants

DEFAULT_FIELD_OPTIONS
DEFAULT_RADIO_OPTIONS
DEFAULT_TEXT_AREA_OPTIONS

### Attributes

method_name[R]
object[R]
object_name[R]

### Public Class Methods

check_box_checked?(value, checked_value) click to toggle source

    # File lib/action_view/helpers/form_helper.rb, line 1163
    def check_box_checked?(value, checked_value)
      case value
      when TrueClass, FalseClass
        value
      when NilClass
        false
      when Integer
        value != 0
      when String
        value == checked_value
      when Array
        value.include?(checked_value)
      else
        value.to_i != 0
      end
    end

new(object_name, method_name, template_object, object = nil) click to toggle source

    # File lib/action_view/helpers/form_helper.rb, line 980
    def initialize(object_name, method_name, template_object, object = nil)
      @object_name, @method_name = object_name.to_s.dup, method_name.to_s.dup
      @template_object = template_object

      @object_name.sub!(/\[\]$/,"") || @object_name.sub!(/\[\]\]$/,"]")
      @object = retrieve_object(object)
      @auto_index = retrieve_autoindex(Regexp.last_match.pre_match) if Regexp.last_match
    end

radio_button_checked?(value, checked_value) click to toggle source

    # File lib/action_view/helpers/form_helper.rb, line 1180
    def radio_button_checked?(value, checked_value)
      value.to_s == checked_value.to_s
    end

value(object, method_name) click to toggle source

    # File lib/action_view/helpers/form_helper.rb, line 1151
    def value(object, method_name)
      object.send method_name if object
    end

value_before_type_cast(object, method_name) click to toggle source

    # File lib/action_view/helpers/form_helper.rb, line 1155
    def value_before_type_cast(object, method_name)
      unless object.nil?
        object.respond_to?(method_name + "_before_type_cast") ?
        object.send(method_name + "_before_type_cast") :
        object.send(method_name)
      end
    end

### Public Instance Methods

retrieve_autoindex(pre_match) click to toggle source

    # File lib/action_view/helpers/form_helper.rb, line 1133
    def retrieve_autoindex(pre_match)
      object = self.object || @template_object.instance_variable_get("@#{pre_match}")
      if object && object.respond_to?(:to_param)
        object.to_param
      else
        raise ArgumentError, "object[] naming but object param and @object var don't exist or don't respond to to_param: #{object.inspect}"
      end
    end

retrieve_object(object) click to toggle source

    # File lib/action_view/helpers/form_helper.rb, line 1122
    def retrieve_object(object)
      if object
        object
      elsif @template_object.instance_variable_defined?("@#{@object_name}")
        @template_object.instance_variable_get("@#{@object_name}")
      end
    rescue NameError
      # As @object_name may contain the nested syntax (item[subobject]) we need to fallback to nil.
      nil
    end

to_boolean_select_tag(options = {}) click to toggle source

    # File lib/action_view/helpers/form_helper.rb, line 1105
    def to_boolean_select_tag(options = {})
      options = options.stringify_keys
      add_default_name_and_id(options)
      value = value(object)
      tag_text = "<select"
      tag_text << tag_options(options)
      tag_text << "><option value=\"false\""
      tag_text << " selected" if value == false
      tag_text << ">False</option><option value=\"true\""
      tag_text << " selected" if value
      tag_text << ">True</option></select>"
    end

to_check_box_tag(options = {}, checked_value = "1", unchecked_value = "0") click to toggle source

    # File lib/action_view/helpers/form_helper.rb, line 1083
    def to_check_box_tag(options = {}, checked_value = "1", unchecked_value = "0")
      options = options.stringify_keys
      options["type"]     = "checkbox"
      options["value"]    = checked_value
      if options.has_key?("checked")
        cv = options.delete "checked"
        checked = cv == true || cv == "checked"
      else
        checked = self.class.check_box_checked?(value(object), checked_value)
      end
      options["checked"] = "checked" if checked
      if options["multiple"]
        add_default_name_and_id_for_value(checked_value, options)
        options.delete("multiple")
      else
        add_default_name_and_id(options)
      end
      hidden = unchecked_value ? tag("input", "name" => options["name"], "type" => "hidden", "value" => unchecked_value, "disabled" => options["disabled"]) : ""
      checkbox = tag("input", options)
      (hidden + checkbox).html_safe
    end

to_content_tag(tag_name, options = {}) click to toggle source

    # File lib/action_view/helpers/form_helper.rb, line 1118
    def to_content_tag(tag_name, options = {})
      content_tag(tag_name, value(object), options)
    end

to_input_field_tag(field_type, options = {}) click to toggle source

    # File lib/action_view/helpers/form_helper.rb, line 1033
    def to_input_field_tag(field_type, options = {})
      options = options.stringify_keys
      options["size"] = options["maxlength"] || DEFAULT_FIELD_OPTIONS["size"] unless options.key?("size")
      options = DEFAULT_FIELD_OPTIONS.merge(options)
      if field_type == "hidden"
        options.delete("size")
      end
      options["type"]  ||= field_type
      options["value"] = options.fetch("value"){ value_before_type_cast(object) } unless field_type == "file"
      options["value"] &&= ERB::Util.html_escape(options["value"])
      add_default_name_and_id(options)
      tag("input", options)
    end

to_label_tag(text = nil, options = {}, &block) click to toggle source

    # File lib/action_view/helpers/form_helper.rb, line 989
    def to_label_tag(text = nil, options = {}, &block)
      options = options.stringify_keys
      tag_value = options.delete("value")
      name_and_id = options.dup

      if name_and_id["for"]
        name_and_id["id"] = name_and_id["for"]
      else
        name_and_id.delete("id")
      end

      add_default_name_and_id_for_value(tag_value, name_and_id)
      options.delete("index")
      options.delete("namespace")
      options["for"] ||= name_and_id["id"]

      if block_given?
        @template_object.label_tag(name_and_id["id"], options, &block)
      else
        content = if text.blank?
          object_name.gsub!(/\[(.*)_attributes\]\[\d\]/, '.\1')
          method_and_value = tag_value.present? ? "#{method_name}.#{tag_value}" : method_name

          if object.respond_to?(:to_model)
            key = object.class.model_name.i18n_key
            i18n_default = ["#{key}.#{method_and_value}".to_sym, ""]
          end

          i18n_default ||= ""
          I18n.t("#{object_name}.#{method_and_value}", :default => i18n_default, :scope => "helpers.label").presence
        else
          text.to_s
        end

        content ||= if object && object.class.respond_to?(:human_attribute_name)
          object.class.human_attribute_name(method_name)
        end

        content ||= method_name.humanize

        label_tag(name_and_id["id"], content, options)
      end
    end

to_number_field_tag(field_type, options = {}) click to toggle source

    # File lib/action_view/helpers/form_helper.rb, line 1047
    def to_number_field_tag(field_type, options = {})
      options = options.stringify_keys
      options['size'] ||= nil

      if range = options.delete("in") || options.delete("within")
        options.update("min" => range.min, "max" => range.max)
      end
      to_input_field_tag(field_type, options)
    end

to_radio_button_tag(tag_value, options = {}) click to toggle source

    # File lib/action_view/helpers/form_helper.rb, line 1057
    def to_radio_button_tag(tag_value, options = {})
      options = DEFAULT_RADIO_OPTIONS.merge(options.stringify_keys)
      options["type"]     = "radio"
      options["value"]    = tag_value
      if options.has_key?("checked")
        cv = options.delete "checked"
        checked = cv == true || cv == "checked"
      else
        checked = self.class.radio_button_checked?(value(object), tag_value)
      end
      options["checked"]  = "checked" if checked
      add_default_name_and_id_for_value(tag_value, options)
      tag("input", options)
    end

to_text_area_tag(options = {}) click to toggle source

    # File lib/action_view/helpers/form_helper.rb, line 1072
    def to_text_area_tag(options = {})
      options = DEFAULT_TEXT_AREA_OPTIONS.merge(options.stringify_keys)
      add_default_name_and_id(options)

      if size = options.delete("size")
        options["cols"], options["rows"] = size.split("x") if size.respond_to?(:split)
      end

      content_tag("textarea", options.delete('value') || value_before_type_cast(object), options)
    end

value(object) click to toggle source

    # File lib/action_view/helpers/form_helper.rb, line 1142
    def value(object)
      self.class.value(object, @method_name)
    end

value_before_type_cast(object) click to toggle source

    # File lib/action_view/helpers/form_helper.rb, line 1146
    def value_before_type_cast(object)
      self.class.value_before_type_cast(object, @method_name)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.