所以我接下來的教程有一個很好的方法來構建一個選擇多年的下拉選擇菜單。在這個select標籤助手中,爲什麼.push?
導師非常故意在下面的第6行代碼中使用.push
。 爲什麼?它會推動什麼?我從來沒有見過使用它的這種方式。
# payment.rb
def self.year_options
(Date.today.year..(Date.today.year+10)).to_a
end
# new.html.erb
<%= p.select :card_expires_year,
options_for_select(Payment.year_options.push),
{include_blank:'Year'},
'data-stripe'=>'exp-year',
class:'form-control',
required:true
%>
好問題。我想知道同樣的事情。 – jeznag