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

Hobo do not integrate with web-console gem (missing method). #196

Open
pienkowskip opened this issue Dec 3, 2017 · 1 comment
Open

Hobo do not integrate with web-console gem (missing method). #196

pienkowskip opened this issue Dec 3, 2017 · 1 comment

Comments

@pienkowskip
Copy link

Rails adds (probably by default) a web-console gem which allows developer to use irb in terminal.

But there is a problem in WebConsole::View. Hobo extension of a ActionView::Helpers::TranslationHelper do not see method normalize_args which is defined by HoboTranslationsNormalizerHelper. This causes all errors in Rails to end up with HTTP 500 and messege "We're sorry, but something went wrong." instead of classic developer view of error (stack trace, http params, etc). Here goes excerpt of my stack trace of error:

Started GET "/admin/front" for 127.0.0.1 at 2017-12-03 12:18:50 +0100
  ActiveRecord::SchemaMigration Load (0.3ms)  SELECT "schema_migrations".* FROM "schema_migrations"

ActionController::RoutingError (No route matches [GET] "/adm
[console_log.txt](https://github.com/Hobo/hobo/files/1524694/console_log.txt)
[console_log.txt](https://github.com/Hobo/hobo/files/1524695/console_log.txt)
[console_log.txt](https://github.com/Hobo/hobo/files/1524696/console_log.txt)


in/front"):
  actionpack (4.2.6) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
  web-console (2.3.0) lib/web_console/middleware.rb:28:in `block in call'
(...)
  /usr/lib/ruby/2.3.0/webrick/server.rb:296:in `block in start_thread'


  Rendered /var/lib/gems/2.3.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (7.3ms)
(...)
  Rendered /var/lib/gems/2.3.0/gems/web-console-2.3.0/lib/web_console/templates/index.html.erb (298.5ms)

ActionView::Template::Error: undefined method `normalize_args' for #<WebConsole::View:0x0055a4b654c170>
	from /var/lib/gems/2.3.0/gems/hobo-2.2.6/lib/hobo/extensions/action_view/translation_helper.rb:13:in `translate'
	from /var/lib/gems/2.3.0/gems/web-console-2.3.0/lib/web_console/view.rb:34:in `t'
(...)
	from /usr/lib/ruby/2.3.0/webrick/server.rb:296:in `block in start_thread'

Here goes a full console log:
console_log.txt

I suppose this happens because Hobo version of ActionView::Helpers::TranslationHelper#translate method but the base class (WebConsole::View) is not extended by HoboTranslationsNormalizerHelper. For instance Hobo controllers are extended this way:

HoboTranslationsNormalizerHelper.add_to_controller(klass)

When I monkey patched hobo gem like that (extend):

ActionView::Helpers::TranslationHelper.module_eval do

  def translate(key, options={})
    self.extend(HoboTranslationsNormalizerHelper) unless self.is_a?(HoboTranslationsNormalizerHelper)
    key, options = normalize_args(key, options)
    translation = I18n.translate(scope_key_by_partial(key), options.merge!(:raise => true))
(...)
  end
end

everything worked. But this is not proper way to do it and I have no idea how to do it proper way.

My setup is:

  • ruby 2.3.3
  • hobo 2.2.6
  • rails 4.2.6
  • web-console 2.3.0

Without web-console gem things works fine.

@pienkowskip
Copy link
Author

Well, I can add this code:

WebConsole::View.class_eval do
  include HoboTranslationsNormalizerHelper
end

as a rails initializer. But this do not seems very sweet as well.

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

1 participant