Rails: Using Slim template in ActiveAdmin Arbre

From FVue
Jump to: navigation, search

Problem

I want to use Slim instead of Arbre. How can I use Slim-partials in an Arbre template?

Solution 1: Template

# app/admin/dashboard.rb
render partial: 'admin/foo'
# app/views/admin/_foo.html.slim
ol
  li Slim

Solution 2: Inline

Caveats (prefer using #Solution 1: Template)

  • Use here-doc with single-quotes to prevent string interpolation, otherwise you might receive error 'undefined local variable or method'
  • helper link_to can't be found. Workaround: use full helper path like this: ActionController::Base.helpers.link_to
  • debugger loses track
# app/admin/dashboard.rb
ActiveAdmin.register_page 'Dashboard' do
  content title: 'Dashboard' do
    content_for(:slim_test) do
      slim = <<~'SLIM'
        - list = %i[foo bar]
        ol
          - list.each do |item|
            li #{item}
      SLIM
      Slim::Template.new { slim }.render.html_safe
  end
 
  columns do
    column do
      panel 'Test' do
        text_node content_for(:slim_test)
      end
    end
  end
end

Comments

blog comments powered by Disqus