Human height loss for rails

I need the loss of human heights, for example 5'2, 5'3, 5'4, etc. Preferably something like 4'0 to 8'0. Is there a gem or plugin? I can't seem to find him.

+3
source share
4 answers

Presumably, you would still save it in inches, so that you can generate your own @heightsto go to the_from_collection_for_select parameters, for example:

(56..112).to_a.map { |inch| { id: inch.to_s, name: (inch/12).floor.to_s+'\''+(inch%12).to_s } }

Perhaps with the conversion of an inch to a string output to a helper method.

+3
source

Not sure if this is the best way, but you can try something like this

@heights = (4..7).to_a.collect{|o| 0.upto(11).to_a.collect{|k| ["#{o.to_s+'\'' + k.to_s}",o.to_s + k.to_s]}}.inject([]){|s,v| s | v}

OR better

@heights = (4..7).to_a.collect{|o| 0.upto(11).to_a.collect{|k| ["#{o.to_s+'\'' + k.to_s}",o.to_s + k.to_s]}}.flatten(1)

this will give a structure like <

[["4'0", "40"], ["4'1", "41"], ["4'2", "42"], ["4'3", "43"], ["4'4", "44"]] # and so on..

, , :

@heights.map { |name, id| OpenStruct.new(:value => id, :name => name) } 

,

, OpenStruct,

require 'ostruct' 

select:

<%= select_tag "Height", options_from_collection_for_select(@heights,'value','name'), html_options = { :onChange=> "height_changed();"} %>
+2

https://github.com/AlexanderZaytsev/height

def height
(121..244).to_a.collect{|k| ["#{Height.new(k).to_s(:default, :metric)}","#{Height.new(k).to_s(:default, :imperial)}","#{Height.new(k).feet}"]}
end

[["1m 21cm", "4 ft 0 in", "4"], ["1m 22cm", "4 ft 0 in", "4"], ["1m 23cm", "4 ft 0 in", "4"], ["1m 24cm", "4 ft 1 in", "4.08"]

<%= f.input :how_tall_are_you, label: "How tall are you ? (in feet  and Cm)", collection: height.map { |cm, inc, value| ["#{cm} - #{inc}", "#{value}"] }  ,prompt: "-Please select one-",input_html: { class: 'form-control input-lg', required: true} %>
0

:

<%=
  n.select :height, 
  options_for_select((36..96).to_a.map { |inch| 
    { 
      id: inch.to_s, 
      name: (inch/12).floor.to_s+'\''+(inch%12).to_s+'"' 
    }
  }),
  {},
  id: 'height' 
%>

:

height dropdown

HTML :

<select id="height" name="height_select">
<option value="{:id=>&quot;36&quot;, :name=>&quot;3'0\&quot;&quot;}">{:id=&gt;"36", :name=&gt;"3'0\""}</option>
<option value="{:id=>&quot;37&quot;, :name=>&quot;3'1\&quot;&quot;}">{:id=&gt;"37", :name=&gt;"3'1\""}</option>
<option value="{:id=>&quot;38&quot;, :name=>&quot;3'2\&quot;&quot;}">{:id=&gt;"38", :name=&gt;"3'2\""}</option>
....

, , (). (user_height).

<%= 
  n.select :height, 
  options_for_select(
    (36..96).to_a.map { |inch| 
      { 
        id: inch.to_s, 
        name: (inch/12).floor.to_s+'\''+(inch%12).to_s+'"' 
      } 
    }.collect{ |p| 
      [p[:name], 
      p[:id].to_i]
    },
    user_height),
    {},
    id: 'height' 
%>

height downdown leo

HTML-:

<select id="height" name="height_select">
<option value="36">3'0"</option>
<option value="37">3'1"</option>
<option value="38">3'2"</option>
...
<option selected="selected" value="69">5'9"</option>
...
</select>

, , !

.

0

All Articles