Insert a non-input row into a Formtasic form

前端 未结 4 773
谎友^
谎友^ 2020-12-13 21:29

I am using Formtastic 2.1.1 in Rails 3.2 (with Active Admin) and I want to insert a row into my form that does not have an input field present. Is this poss

4条回答
  •  情歌与酒
    2020-12-13 21:56

    To insert any custom code in any place, you may use f.form_buffers.last:

    form do |f|
      f.form_buffers.last << "

    Hello world!

    ".html_safe # The simple way ft = f.template # just a helper variable f.inputs "Foo" do f.input :title f.form_buffers.last << ft.content_tag(:li) do ft.content_tag(:p, "Hello again!") + ft.tag(:input, type: :hidden, name: "bar[]", value: "baz") end f.input :path end end

    Just be careful about the HTML structure. If you call this from f.inputs block, your code will be placed inside an

      element. On the "form" level, you are inside a
      element.

      A little warning: As with any "undocumented feature" this method may change without warning in any new release.

提交回复
热议问题