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)
-- creatingrange
object, 0 100 (inclusive)..step(1)
-- not needed; delete it. it's saying "step through range 1 @ time" (which default anyway). convertsrange
enumerator
..to_a
-- not needed; delete it. convertingenumerator
array
..collect {|r| ["#{r} %", r] }
-- mappingarray
new list of arrays, like:[["0 %", 0], ["1 %", 1], ..., ["100 %", 100]]
. (this method work fine onrange
orenumerator
object, since both classes include this methodenumerable
module. hence why above 2 steps can both removed!)f.select :done_ratio, (...)
-- creating htmlselect
element calleddone_ratio
, above names/values.
Comments
Post a Comment