【发布时间】:2014-01-29 18:56:12
【问题描述】:
我是 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 或
这是我的代码:
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 ruby ruby-on-rails-3 activeadmin