0

如果属性值为空白,我CustomInput < SimpleForm::Inputs::Base想避免渲染。IOW,我想避免渲染所有的包装器和组件。我可以在控件中执行此操作以避免if model.attribute.blank?为模板中的每个控件进行编写吗?

4

1 回答 1

0

Just subclass the FormBuilder and override the input method

class MyFormBuilder < SimpleForm::FormBuilder

  def input(attribute_name, options = {}, &block)
    if @template.my_action_show?
      return if @object.send(attribute_name).blank?
    end 
    super
  end

my_action_show? is just custom ApplicationHelper method that checks if

params[:action]=='show'
于 2012-12-10T15:24:54.627 回答