我是Ruby on Rails的新手,我无法根据单词的数量来更改单词的结尾。
在下面的代码附近,您会看到我写的
h3 "The deal has #{deal.prizes.where(:prize_type => u).count} #{u}
这里的“ u”采用名为PRIZE_TYPE的数组中的值之一。我该怎么做
如果count = 1,则显示“该交易有1个头奖奖金”
如果count = 4,则显示“该交易有4个头奖奖励S
注意:计数不能为0或<0
这是我的代码:
panel "Details of Prizes" do PRIZE_TYPES.each do |u| table_for deal.prizes.where(:prize_type => u) do |t| h3 "The deal has #{deal.prizes.where(:prize_type => u).count} #{u}s initially set in the campaign for a total value of #{custom_number_to_currency (deal.category_prizes_total_initial_value(u)) }", class: 'title-within-table' if deal.prizes.where(:prize_type => u).count > 0 # if there is at least one record of 'jackpot prize' t.column("Prize") { |prize| link_to( image_tag( prize.prize_image_url, class: 'main_img_in_admin_interface' ), admin_prize_path(prize), target: :blank ) } t.column("Name") { |prize| link_to prize.prize_name, admin_prize_path(prize), target: :blank } t.column("Category") { |prize| prize.prize_category } t.column("Initial quantity") { |prize| prize.prize_initial_stock_quantity } end # end of Prize.each... end # end of panel "details of prizes"
和PRIZE_TYPE常量:
PRIZE_TYPES = ["Jackpot prize","Consolation prize", "awesome prize"]
我是Ruby on Rails的新手,我无法根据单词的数量来更改单词的结尾。在下面的代码顶部附近,您会看到我写了h3“该交易具有#{deal.prizes ....