Rails形式的条件html-更好的方法?

时间:2018-11-28 09:23:08

标签: ruby-on-rails ruby twitter-bootstrap bootstrap-4 haml

我有一个带条件引导程序的表单:

= simple_form_for(@user) do |f|
    = f.input :first_name
    - if f.object.new_record?
      %button.btn.btn-primary{"data-target" => "#accordion", "data-toggle" => "collapse", :type => "button"}
        .fa.fa-cog
        More options
      #accordion.collapse
      = f.input :many_more_fields
    - else
      = f.input :many_more_fields

是否有更好的方法使css有条件,而不必重复= f.input :many_more_fields。 CSS部分:

  %button.btn.btn-primary{"data-target" => "#accordion", "data-toggle" => "collapse", :type => "button"}
    .fa.fa-cog
    More options
  #accordion.collapse

P.S。有什么想法,除了为= f.input :many_more_fields创建局部视图?

0 个答案:

没有答案