markets / maily

📫 Rails Engine to preview emails in the browser
https://rubygems.org/gems/maily
MIT License
707 stars 31 forks source link

Engine doesn't render #18

Closed Frexuz closed 7 years ago

Frexuz commented 7 years ago

Not sure what I'm doing wrong.

NoMethodError in Maily::Emails#index

---

Showing /Users/kristiangerardsson/www/example.com/app/views/application/_account_popup_menu.html.erb where line #1 raised:

undefined method `employee_path' for #<#<Class:0x007f9a37a04cf8>:0x007f9a38076438>

---

app/views/application/_account_popup_menu.html.erb:1:in `_app_views_application__account_popup_menu_html_erb___2286500346444814438_70150160003460'
app/views/application/_app_bar.html.erb:6:in `_app_views_application__app_bar_html_erb__2941068856054159746_70150140576160'
app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___763355335627937910_70150166256700'

Seems it tried to render the apps normal layout. Just browsing localhost:3000/maily

I just used the generator to install the config and hooks file, and haven't changed them.

Any ideas?

markets commented 7 years ago

hi @Frexuz, did you restart the server after the installation?

Frexuz commented 7 years ago

Yes

markets commented 7 years ago

Weird, I'm actually using it in 4 Rails (v4, v5) apps with no problems. Is it this app open source? Or could you push some code that reproduces the error? I'd take a look. Thanks.

Frexuz commented 7 years ago

I tried in a new app. /maily works fine. So its something with my app. However, the install command is a bit broken.

Running this on a 100% new app, after adding the gem.

➜  maily-test git:(master) ✗ rails g maily:install
Running via Spring preloader in process 7903
       route  mount Maily::Engine, at: 'maily'
      create  config/initializers/maily.rb
/Users/kristiangerardsson/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/maily-0.6.0/lib/maily.rb:32:in `join': no implicit conversion of nil into String (TypeError)
    from /Users/kristiangerardsson/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/maily-0.6.0/lib/maily.rb:32:in `load_emails_and_hooks'
    from /Users/kristiangerardsson/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/maily-0.6.0/lib/maily/mailer.rb:14:in `all'
    from /Users/kristiangerardsson/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/maily-0.6.0/lib/generators/maily/install_generator.rb:27:in `build_hooks'
    from /Users/kristiangerardsson/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/maily-0.6.0/lib/generators/maily/install_generator.rb:10:in `install'
    from /Users/kristiangerardsson/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/thor-0.19.4/lib/thor/command.rb:27:in `run'
    from /Users/kristiangerardsson/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/thor-0.19.4/lib/thor/invocation.rb:126:in `invoke_command'
    from /Users/kristiangerardsson/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/thor-0.19.4/lib/thor/invocation.rb:133:in `block in invoke_all'
    from /Users/kristiangerardsson/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/thor-0.19.4/lib/thor/invocation.rb:133:in `each'
    from /Users/kristiangerardsson/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/thor-0.19.4/lib/thor/invocation.rb:133:in `map'
    from /Users/kristiangerardsson/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/thor-0.19.4/lib/thor/invocation.rb:133:in `invoke_all'
    from /Users/kristiangerardsson/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/thor-0.19.4/lib/thor/group.rb:232:in `dispatch'
    from /Users/kristiangerardsson/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/thor-0.19.4/lib/thor/base.rb:444:in `start'
    from /Users/kristiangerardsson/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.1.2/lib/rails/generators.rb:269:in `invoke'
    from /Users/kristiangerardsson/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.1.2/lib/rails/commands/generate/generate_command.rb:24:in `perform'
    from /Users/kristiangerardsson/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/thor-0.19.4/lib/thor/command.rb:27:in `run'
    from /Users/kristiangerardsson/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/thor-0.19.4/lib/thor/invocation.rb:126:in `invoke_command'
    from /Users/kristiangerardsson/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/thor-0.19.4/lib/thor.rb:369:in `dispatch'
    from /Users/kristiangerardsson/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.1.2/lib/rails/command/base.rb:63:in `perform'
    from /Users/kristiangerardsson/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.1.2/lib/rails/command.rb:44:in `invoke'
    from /Users/kristiangerardsson/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.1.2/lib/rails/commands.rb:16:in `<top (required)>'
    from /Users/kristiangerardsson/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.1.2/lib/active_support/dependencies.rb:292:in `require'
    from /Users/kristiangerardsson/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.1.2/lib/active_support/dependencies.rb:292:in `block in require'
    from /Users/kristiangerardsson/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.1.2/lib/active_support/dependencies.rb:258:in `load_dependency'
    from /Users/kristiangerardsson/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.1.2/lib/active_support/dependencies.rb:292:in `require'
    from /Users/kristiangerardsson/www/maily-test/bin/rails:9:in `<top (required)>'
    from /Users/kristiangerardsson/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.1.2/lib/active_support/dependencies.rb:286:in `load'
    from /Users/kristiangerardsson/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.1.2/lib/active_support/dependencies.rb:286:in `block in load'
    from /Users/kristiangerardsson/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.1.2/lib/active_support/dependencies.rb:258:in `load_dependency'
    from /Users/kristiangerardsson/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.1.2/lib/active_support/dependencies.rb:286:in `load'
    from /Users/kristiangerardsson/.rbenv/versions/2.3.1/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /Users/kristiangerardsson/.rbenv/versions/2.3.1/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from -e:1:in `<main>'
➜  maily-test git:(master) ✗ rails g maily:install
Running via Spring preloader in process 8324
       route  mount Maily::Engine, at: 'maily'
   identical  config/initializers/maily.rb
      create  lib/maily_hooks.rb

Re-running the command makes it pass.

Frexuz commented 7 years ago

My application does

Processing by Maily::EmailsController#index as HTML
  Rendering /Users/kristiangerardsson/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/maily-0.6.0/app/views/maily/emails/index.html.erb within layouts/application

vs (a clean repo with maily)

Processing by Maily::EmailsController#index as HTML
  Rendering /Users/kristiangerardsson/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/maily-0.6.0/app/views/maily/emails/index.html.erb within layouts/maily/application

so, it's rendering layouts/application vs layouts/maily/application

any further ideas?

Frexuz commented 7 years ago

Vendored the gem into the app's local /vendor and loaded the gem from there

changed class EmailsController < ApplicationControllerto class EmailsController < Maily::ApplicationController and that worked.

Somehow my ApplicationController loaded, and not the gem's. Not sure that is a correct solution tho. What you think?

markets commented 7 years ago

Hi @Frexuz about the error with rails g maily:install on first run, it was fixed here:

https://github.com/markets/maily/pull/17 (this commit => https://github.com/markets/maily/pull/17/commits/bf6ec1665219e00f431b42a6ebce24a9b9450934)

So if you change to use 0.6.1, this is fixed.

About the problem with Maily::ApplicationController, I'm going to take look now and I'll ping you later. But yes, probably forcing that namespace will solve the issue.

Thanks for all this info!