ActionMailer preview_path is not the RSpec default - ruby-on-rails

I have an app that's throwing the following error every time the environment is loaded.
Action Mailer preview_path is not the RSpec default. Preview path is set to: spec
I'm not even sure what the preview_path here is or where it might be configured. Is there a way to adjust this or disable it?
Thanks!

You probably have the following in your config/environment/development.rb file:
config.action_mailer.preview_path = 'spec/'
As for what the preview path is, it's to preview emails in your browser.
Not sure why it would be erroring. Perhaps try commenting out the config line above if you don't need email previewing?

Related

Ruby on Rails: configure web_console in initializer

I am using the web_console gem and I would like to add some IPs to the whitelist. For reasons that would probably go to far to explain, can't simply add something to the config/application.rb or config/environments/development.rb. However I can create an initializer config/initializers/.
I simple tried this in config/initializers/99-webconsole.rb, but while the file is loaded (--> debug message is shown), the web console does not seem to pick up my settings.
Rails.application.configure do
config.web_console.whitelisted_ips = '10.10.0.0/16'
p "Debug: this is loaded."
end
I assume it's related to some kind of race condition? Providing the same line in config/environments/development.rb works, but as said, I sadly can not change that file.
Based on this code https://github.com/rails/web-console/blob/e3dcf4c588af526eafcf1ce9413e62d846599538/lib/web_console/railtie.rb#L59
maybe there is a code in your initializer that configuring config.web_console.permissions, so your whitelisted_ips config is ignored
whitelisted_ips is also deprecated
and have you checked that you are using v4.2.0, the permissions was buggy and fixed by this commit https://github.com/rails/web-console/commit/6336c89385b58e88b2661ea3dc42fe28651d6296

Zeitwerk error on devise mailer in production environment

I have Rails 6, my preview class located in
mailer/previews/devise_mailer_preview.rb:
class DeviseMailerPreview < ActionMailer::Preview
...
end
And when I run application locally, everything is going fine, I can see my email previews on http://localhost:3000/rails/mailers/devise_mailer/confirmation_instructions address. But now Im trying to deploy application on server, and found that when I run bundle exec rails c production, I got the error:
/home/deploy/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/zeitwerk-2.3.0/lib/zeitwerk/loader/callbacks.rb:17:in
`on_file_autoloaded': expected file
/home/deploy/project/releases/20200627024908/app/mailer/previews/devise_mailer_preview.rb
to define constant Previews::DeviseMailerPreview, but didn't
(Zeitwerk::NameError)
After that I've checked locally RAILS_ENV=production rails c, and got same.
If I will rename DeviseMailerPreview class to Previews::DeviseMailerPreview, it will be broken and I cannot see emails on development, because Rails 6, accordingly to docs, expect exactly that name.
More of that, I've found in this article, that zeitwerk can be configured with autoload_paths param to avoid ruby's NameError. I found that I have it my config/application.rb:
config.load_defaults 6.0
Anyway I tried to add same row in my config/environments/production.rb file, but it didn't help.
What am I doing wrong and how can I fix it? Thanks in advance!
Add preview_path to the autoload_paths and zeitwerk will expect DeviseMailerPreview constant to be defined.
# development.rb
config.action_mailer.preview_path = Rails.root.join("app/mailers/previews")
# application.rb
config.autoload_paths << Rails.root.join("app/mailers/previews")
Your Mailer preview file is located in mailer/previews/devise_mailer_preview.rb, so I'm assuming it's full path is app/mailer/previews/devise_mailer_preview.rb
The docs says
In the above example, the preview class for UserMailer should be named UserMailerPreview and located in test/mailers/previews/user_mailer_preview.rb
So put your devise_mailer_preview.rb file to test/mailers/previews/devise_mailer_preview.rb
or in your config/application.rb add this line and restart:
config.action_mailer.preview_path = "#{Rails.root}/app/mailers/previews"
Actually the answer was in the docs itself.
In Rails 6, previews are added to the autoload paths only if options.show_previews is true, which is not by default in the production environment. See the source code here.
The reason for this is that previews are supposed to be an aid for development, and they are generally not something you want to be able to look at in production.
However, you can set that flag to true in production if you want.
There's another derivative: By storing the previews under app/mailers, Rails is going to eager load them because app/mailers is in the autoload paths. If app/mailers/previews is not in the autoload paths, eager loading will fail due to the namespace mismatch. Either you have them enabled in all environments, or else is better to have them in a separate location, like the default.

Rails 5 missing template that was added to lookup

I have added into application.rb string
config.paths['app/views'] << 'app/views/cabinet'
and created a view 'app/views/cabinet/index.html.slim'.
But when I go to route localhost:3000/manager/pages (It uses layout manager if it make sence), Rails gives the error
Manager::PagesController#index is missing a template for this request format and variant.
What I'm doing wrong?
I am not sure what you are trying to do by overriding the mapping for the location of app/views but it doesn't sound like a good idea to me.
Without knowing more about your code I would suggest you remove that config line from application.rb and simply use:
render 'cabinet/index'
from PagesController#index action.

Skip link default behavior rails 4.2

I have a little problem: I have a file stored in public/uploads//paper/foo/bar. This file is stored here by carrierwave (gem for file upload). Now, I want to put a link in my project to this file, but if I do like this: <%=a.name%> I get a routing error like this: No route matches [GET] "/uploads/paper/foo/bar/file.pdf".
How can I skip this default behavior of links in rails?
This probably due to config.serve_static_files is not set to true in config/enviroments/development.rb or whichever environment you are running (defaults to true for development and false for production)

Rails 3.1.1 - Asset Pipeline - asset.prefix not working with resource :assets

I am having an issue with the asset pipeline, I already have a resource / controller called assets. So i have changed assets.prefix option to "/externals".
config.assets.prefix = '/externals'
This simple dose not work unless i remove:
resources: assets
Then all works as expected.
I am not sure how to write a test to prove this but i have created a app to showcase it.
https://github.com/nodrog/asset-pipeline-issue
If you run the app, and visit '/products' all will work, then go to the routes file and change the variable create_bug to true.
We have looked into https://github.com/rails/rails/blob/master/actionpack/lib/sprockets/helpers/rails_helper.rb, and then added a debugger to the asset_path method.
This method is not called, if you but a debugger in the javascript_include_tag method. And run method(:asset_path).source_location, it tells you it is calling the method from default routes not from the sprockets helper.
Any help would be greatly appreciated...
UPDATE:
I reported this to the rails people, and they fixed it. The fix is now in the master branch.
https://github.com/rails/rails/issues/3643#issuecomment-2775938

Resources