How to embed raw html in active_admin formtastic

I am trying to create a form with formtastic inside the active_admin model. The problem is that I need a specific script tag and other raw HTML elements directly inside or around the form.

I do this with a normal form block:

form do |f| f.inputs :name => "User Details", :for => :user do |user_form| user_form.input :first_name, :required => true ... 

How to insert a simple div tag directly between them? Or even a script tag?

I thought about using render :partial , but I want to know if the above method is possible. Thanks!

+4
source share
3 answers

You can insert a div or javascript as follows:

  f.form_buffers.last << content_tag(:div, "Div content here") f.form_buffers.last << javascript_tag("alert('hi');") 
+7
source

In current ActiveAdmin form_buffers is deprecated. Instead, you can do the following:

 insert_tag(Arbre::HTML::Div) { content_tag(:span, "foo") } 
+5
source

Active admin created DSL on top of Formtastic according to their docs

https://github.com/activeadmin/activeadmin/blob/master/docs/5-forms.md

So now you can:

 form do |f| f.semantic_errors(*f.object.errors.keys) import_errors = self.controller.instance_variable_get("@errors") if import_errors.present? ul class: 'errors' do import_errors.each do |e| li e end end end # ... end 
+1
source

Source: https://habr.com/ru/post/1412604/


All Articles