Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't create custom components #43

Closed
senid231 opened this issue Aug 27, 2015 · 4 comments
Closed

can't create custom components #43

senid231 opened this issue Aug 27, 2015 · 4 comments

Comments

@senid231
Copy link

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?)

@timoschilling
Copy link
Member

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?

@senid231
Copy link
Author

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

@senid231
Copy link
Author

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

@timoschilling
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants