activeadmin/arbre

can't create custom components

senid231 opened this issue · 4 comments

i've created simple rails project
put gem 'arbre' into Gemfile
create file app/lib/arbre_components/panel.rb:

module ArbreComponents
  class Panel < Arbre::Component
    builder_method :panel

    def build(title, attrs = {})
      super(attrs)
      h3 title, class: 'panel-title'
    end
  end
end

generate controller with rails g Welcome index and set it to root
and change text in app/views/welcome/index.html.erb:

<%= Arbre::Context.new { panel 'welcome' } %>

on page render i get an error:

Started GET "/" for 127.0.0.1 at 2015-08-27 20:23:55 +0300
Processing by WelcomeController#index as HTML
  Rendered welcome/index.html.erb within layouts/application (4.1ms)
Completed 500 Internal Server Error in 21ms (ActiveRecord: 0.0ms)

ActionView::Template::Error (undefined method `panel' for :Arbre::Context):
    1: <%= Arbre::Context.new { panel 'welcome' } %>
  app/views/welcome/index.html.erb:1:in `block in _app_views_welcome_index_html_erb__3263134319601290878_43964100'
  app/views/welcome/index.html.erb:1:in `new'
  app/views/welcome/index.html.erb:1:in `_app_views_welcome_index_html_erb__3263134319601290878_43964100'


  Rendered /home/senid/.rvm/gems/ruby-2.2.2/gems/actionpack-4.2.3/lib/action_dispatch/middleware/templates/rescues/_source.erb (15.7ms)
  Rendered /home/senid/.rvm/gems/ruby-2.2.2/gems/actionpack-4.2.3/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (3.7ms)
  Rendered /home/senid/.rvm/gems/ruby-2.2.2/gems/actionpack-4.2.3/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.2ms)
  Rendered /home/senid/.rvm/gems/ruby-2.2.2/gems/actionpack-4.2.3/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb within rescues/layout (39.6ms)
  Rendered /home/senid/.rvm/gems/ruby-2.2.2/gems/web-console-2.2.1/lib/web_console/templates/_markup.html.erb (0.5ms)
  Rendered /home/senid/.rvm/gems/ruby-2.2.2/gems/web-console-2.2.1/lib/web_console/templates/_inner_console_markup.html.erb within layouts/inlined_string (0.5ms)
  Rendered /home/senid/.rvm/gems/ruby-2.2.2/gems/web-console-2.2.1/lib/web_console/templates/_prompt_box_markup.html.erb within layouts/inlined_string (0.4ms)
  Rendered /home/senid/.rvm/gems/ruby-2.2.2/gems/web-console-2.2.1/lib/web_console/templates/style.css.erb within layouts/inlined_string (0.5ms)
  Rendered /home/senid/.rvm/gems/ruby-2.2.2/gems/web-console-2.2.1/lib/web_console/templates/console.js.erb within layouts/javascript (20.9ms)
  Rendered /home/senid/.rvm/gems/ruby-2.2.2/gems/web-console-2.2.1/lib/web_console/templates/main.js.erb within layouts/javascript (0.4ms)
  Rendered /home/senid/.rvm/gems/ruby-2.2.2/gems/web-console-2.2.1/lib/web_console/templates/error_page.js.erb within layouts/javascript (0.5ms)
  Rendered /home/senid/.rvm/gems/ruby-2.2.2/gems/web-console-2.2.1/lib/web_console/templates/index.html.erb (44.9ms)

what have i done wrong?)

You need to require the app/lib/arbre_components/panel.rb file someware or whats happen if you call ArbreComponents::Panel in your rails console?

when i rewrite app/views/welcome/index.html.erb like this

<% ArbreComponents::Panel %>
<%= Arbre::Context.new { panel 'welcome' } %>

render works fine.
i think problem in autoloading. i should explicitly require panel.rb

i added line require_relative '../lib/arbre_components/panel'
to app/helpers/application_helper.rb.
But i think there is should be prettier way to solve this

ArbreComponents::Panel can't be autoloaded, in the way that Arbre works.
There is not relation between the Class name and the Tag name.

But I agree with you, it should be handled in a nicer way.