【发布时间】:2019-10-31 22:42:07
【问题描述】:
我有一个对象数组,我希望能够使用 collection_radio_button 显示它们,但似乎 collection_radio_buttons 仅适用于数组或 ActiveRecord 对象。有没有办法使用对象数组构建一个 collection_radio_button?
这是我的对象数组
[{:image_url=>"https://assets.braintreegateway.com/payment_method_logo/visa.png?environment=sandbox", :card_type=>"Visa", :last_4=>"0004", :expiration_month=>"10", :expiration_year=>"2019"}, {:image_url=>"https://assets.braintreegateway.com/payment_method_logo/visa.png?environment=sandbox", :card_type=>"Visa", :last_4=>"0004", :expiration_month=>"11", :expiration_year=>"2019"}]
这是我尝试编写的代码,但它不起作用
<%= collection_radio_buttons("cards", :card, @payment_methods, item_wrapper_tag: false) do |b|
b.label { b[:last_4]}
end %>
感谢任何帮助
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-4 ruby-on-rails-5