What does this code in ruby do? -
i new here please gentle me , i'm still newbie in programming , in ruby language.
this combo box , want know goes after change or function calls. can please tell me goes or does? thanks
<p><%= f.select :done_ratio, ((0..100).step(1).to_a.collect {|r| ["#{r} %", r] }), :required => @issue.required_attribute?('done_ratio') %></p>
it creating html select (dropdown) box, values: 0 %, 1 %, 2 %, ..., 100 %.
the field submitted part of form. may or may not required field, depending on value of @issue.required_attribute?('done_ratio'). (this presumably method in issue model, can found in ./app/models/issue.rb.)
breaking down:
(0..100)-- creatingrangeobject, 0 100 (inclusive)..step(1)-- not needed; delete it. it's saying "step through range 1 @ time" (which default anyway). convertsrangeenumerator..to_a-- not needed; delete it. convertingenumeratorarray..collect {|r| ["#{r} %", r] }-- mappingarraynew list of arrays, like:[["0 %", 0], ["1 %", 1], ..., ["100 %", 100]]. (this method work fine onrangeorenumeratorobject, since both classes include this methodenumerablemodule. hence why above 2 steps can both removed!)f.select :done_ratio, (...)-- creating htmlselectelement calleddone_ratio, above names/values.
Comments
Post a Comment