fgrehm/letter_opener_web

NameError `letter_opener_web'

Closed this issue · 5 comments

When trying to access /letter_opener

Showing C:/Dev/Ruby21-x64/lib/ruby/gems/2.1.0/gems/letter_opener_web-1.3.0/app/views/letter_opener_web/letters/index.html.erb where line #5 raised:

undefined local variable or method `letter_opener_web' for #<#<Class:0x0000000dbbeec0>:0x0000000dbe3630>

Beginning of trace:

letter_opener_web (1.3.0) app/views/letter_opener_web/letters/index.html.erb:5:in `_____ev__uby___x___lib_ruby_gems_______gems_letter_opener_web_______app_views_letter_opener_web_letters_index_html_erb___821572538_115672740'
actionview (4.2.0) lib/action_view/template.rb:145:in `block in render'
activesupport (4.2.0) lib/active_support/notifications.rb:166:in `instrument'
actionview (4.2.0) lib/action_view/template.rb:333:in `instrument'
actionview (4.2.0) lib/action_view/template.rb:143:in `render'
actionview (4.2.0) lib/action_view/renderer/template_renderer.rb:54:in `block (2 levels) in render_template'
actionview (4.2.0) lib/action_view/renderer/abstract_renderer.rb:39:in `block in instrument'
activesupport (4.2.0) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.0) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.0) lib/active_support/notifications.rb:164:in `instrument'

I have followed the instructions (with of course the gems in the gemfile),

mount LetterOpenerWeb::Engine, at: "/letter_opener", as: 'letter_opener'

config.action_mailer.delivery_method = :letter_opener # or letter_opener_web

I had managed to make it work at some point, but cannot figure out what goes wrong this time...

Ok, I just realized the views were using the path helper letter_opener_web, so redefining the path helper as: 'letter_opener' is what made it crash.

I don't know how/if it's a good idea to make a fix for that however.

I'm mounting the engine like the README describes and I get the same exception. I don't think it's related to the alias in the route.

I think the engine itself should not use in its views the routing proxy method as described in the engine Rails guide.

You'd probably want to change the tests to use a dummy app that works exactly like a real Rails app that would mount the engine as described in the README to ensure the tests are testing a real life situation, like it was already mentioned in a comment: #26 (comment)

Edit: to be precise, I didn't mount it exactly like in the README, I mounted the engine inside a namespace and it breaks the gem.

Same issue here. Trying to mount it inside a namespace will break the gem.

This works:

      if Rails.env.development? || Rails.env.staging?
        mount LetterOpenerWeb::Engine, at: 'admin/letter_opener'
      end

      # Admin pages
      namespace :admin do
        mount Resque::Server.new, at: 'resque'
        get '/', action: 'index'

This doesn't:

      # Admin pages
      namespace :admin do
        mount Resque::Server.new, at: 'resque'

        if Rails.env.development? || Rails.env.staging?
          mount LetterOpenerWeb::Engine, at: 'letter_opener'
        end

        get '/', action: 'index'

I'm glad I found this article, at least I can easily work-around the issue now.

I was also affected by this issue, using the latest version of the gem. If I had an alias on the route, I would get an exception just the like author of the issue. I didn't have much time to trace it further, but the error would occur only in production (and not in development)!

Removing the alias fixed the issue for me.

That was fixed in #64, released in v1.3.2. Thanks a lot @pseudomuto!