Unitialized contant Premailer in Rails 5.1
abhinavc opened this issue · comments
Hi,
I am not sure if this is an issue. But I have a Rails 5.1 project and I'm trying to include premailer-rails in it.
An odd thing I noticed was that even after adding the gem 'premailer-rails', I cannot see Premailer constant in rails console
Perhaps this is expected. But then how do I call something like Premailer::Rails::Hook.perform(mail)
as mentioned in the documentation?
Thanks
Abhinav
As it says in the README:
premailer-rails processes all outgoing emails by default.
So you don't have to do anything there.
As to why the Premailer
constant is not available in the Rails console, I don't know. Are you sure you have the gem available in development and not just production?
Actually I don't think I have the gem available in development. It does not show up in $LOAD_PATH.
Also, I noticed that the gem's directory structure is different from those of other gems. In particular, gem 'xyz'
will have a file called lib/xyz.rb
. But premailer-rails
doesn't have a premailer-rails.rb
file in it's lib/
. What it has is lib/premailer/rails.rb'
. It's this file that has the class/module declarations. But I'm not sure if its getting loaded
I was therefore wondering if this non-standard directory structure has something to do with it. Also
gem which premailer-rails
gives the following message
ERROR:
Can't find ruby library file or shared library premailer-rails
whereas for every other gem (including premailer
), I seem to get a path.
Thanks for your help
Abhinav
Oh, and to answer your question, the gem is not included in any specific group (development/production etc). Hence, I would think it would be available in every environment.
This is how it's been included in my Gemfile
gem 'premailer-rails', '~> 1.10'
The loading is fine. Here's more about gem names with dashes in them and how the loading works: https://guides.rubygems.org/name-your-gem/
I just confirmed that everything is working by following these steps:
$ rails new foo
- Append
gem 'premailer-rails', '~> 1.10'
toGemfile
$ bundle
$ rails console
> Premailer #=> Premailer
Thus, it must be something with your setup. What do you get when you do require 'premailer/rails'
?
Yes, I figured a little afterwards that it couldn't have been the dash in the gem name that was causing the problem
So, I did a fresh checkout, commented out everything in the Gemfile and then started adding the gems back one-by-one again (starting with premailer-rails) to see when the problem shows up again
I can't explain it - but the two problem gems seem to be gem spring
and gem spring-watcher-listen
.
They're required only in the development group. Once commented out, I can see Premailer
in the dev console
Or, it could be the interplay of spring
with some other gem
Thanks for looking into the issue though
spring stop
is your friend here. Always try that first before going bananas 😂