我有一个Formtastic单选按钮集合,它由许多类型填充:
<%= f.input :type_id, :validate => true, :as => :radio, :collection => Type.where(:object_type => 'Post') %>但是,我希望有条件地为每个选项添加一个类,因为根据特定条件,需要禁用某些单选按钮。
例如,:member_class =>参数可能是理想的,但我不相信它像:member_label和:member_value那样存在。
Formtastic有能力允许这样做吗?
发布于 2011-10-06 18:27:04
<%= f.input :type_id, :validate => true, :as => :radio,
:collection => Type.where(:object_type => 'Post'),
:input_html => { :class => (:class_name if condition_goes_here) } %>或
<%= f.input :type_id, :validate => true, :as => :radio,
:collection => Type.where(:object_type => 'Post'),
:input_html => { :disabled => (:disabled if condition_goes_here) } %>https://stackoverflow.com/questions/7672611
复制相似问题