我在循環中創建了單選按鈕。Rails radio_button在循環中有條件地檢查
- @annual_packages.each do |plan|
= f.radio_button('plan_id', plan.id)
= plan.title
我怎樣才能使病情檢查無線電是否plan.id == @ plan.id
不起作用:
= f.radio_button('plan_id', plan.id, checked: (plan.id == @plan.id))
循環代碼:
= form_for @organization, url: subscription_create_path, remote: true, method: :post do |f|
- unless @annual_packages.blank?
- @annual_packages.each do |plan|
= f.radio_button('plan_id', plan.id)
= plan.title
你正在嘗試做什麼?你是否試圖將計劃標題顯示爲單選按鈕的標記並接受表單對象的plan_id?什麼是@plan? –