收集的单选按钮

时间:2016-12-16 09:46:00

标签: ruby-on-rails activerecord collections radio-button slim-lang

我正在尝试根据我的数据库中的一个集合返回一组单选按钮,但我没有太多运气。

查看代码

- @merchant_type.each do |mt|
    = form.radio_button mt, mt.name

控制器代码

def new
    @merchant_type =  MerchantType.all
    @merchant = Merchant.new
    @states = State.form_selector
    @products = Product.order(:name => 'asc')
    @properties = Property.where(property_set_id: 1)
    @merchant.trading_hours.build
  end

错误

ActionView::Template::Error (undefined method `#<MerchantType:0x007fd16b55ac50>' for #<Merchant:0x007fd16c481468>):
    6:     p
    7:       b Type
    8:       - @merchant_type.each do |mt|
    9:         = form.radio_button mt, mt.name
  app/views/admin/merchants/_type.html.slim:9:in `block in _app_views_admin_merchants__type_html_slim___3402008222164699688_70268702644260'
  app/views/admin/merchants/_type.html.slim:8:in `_app_views_admin_merchants__type_html_slim___3402008222164699688_70268702644260'

1 个答案:

答案 0 :(得分:0)

试试这个

- @merchant_type.each do |mt|
    = form.radio_button :merchant_type, mt.name