Module: ActionView::Helpers::InstanceTagMethods::ClassMethods

Defined in:
lib/action_view/helpers/form_helper.rb

Instance Method Summary collapse

Instance Method Details

#check_box_checked?(value, checked_value) ⇒ Boolean

Returns:

  • (Boolean)


1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
# File 'lib/action_view/helpers/form_helper.rb', line 1020

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

#radio_button_checked?(value, checked_value) ⇒ Boolean

Returns:

  • (Boolean)


1037
1038
1039
# File 'lib/action_view/helpers/form_helper.rb', line 1037

def radio_button_checked?(value, checked_value)
  value.to_s == checked_value.to_s
end

#value(object, method_name) ⇒ Object



1003
1004
1005
# File 'lib/action_view/helpers/form_helper.rb', line 1003

def value(object, method_name)
  object.send method_name unless object.nil?
end

#value_before_type_cast(object, method_name) ⇒ Object



1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
# File 'lib/action_view/helpers/form_helper.rb', line 1007

def value_before_type_cast(object, method_name)
  unless object.nil?
    if object.respond_to?(method_name)
      object.send(method_name)
    # FIXME: this is AR dependent
    elsif object.respond_to?(method_name + "_before_type_cast")
      object.send(method_name + "_before_type_cast")
    else
      raise NoMethodError, "Model #{object.class} does not respond to #{method_name}"
    end
  end
end