0

我試圖根據數據庫中的集合返回一組單選按鈕,但我沒有多少運氣。集合中的單選按鈕

查看代碼

- @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' 
+0

'MerchantType.all'顯然是觸發了錯誤......但我無法推斷出可能觸發錯誤的原因。我假設你能夠在你的滑軌控制檯中運行'MerchantType.all'嗎? – angkiki

+1

你試過這個「form.radio_button:merchant_type,mt.name」嗎? – Jayaprakash

+0

@Jayaprakash不,我沒有,似乎已經工作 –

回答

0

試試這個

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