See an empty page when access `/rails/mailers` in production - ruby-on-rails

I am using rails 5 and wanted to see the /rails/mailers url in production mode under the authentication.
I am able to implement authentication under the URLs but I can only see a blank page on production(Heroku, review app) but on local I can see the complete page without any issues.
I tried production mode on local as well and that was also working fine.
Running out of ideas in that direction. Thanks in advance.

I got to know,
We are not pushing the spec directory to Heroku, hence there is an empty list of the previews and not able to view any preview at all.

If you use Heroku beware of your .slugignore, you might have 'spec/' in it.
If it is the case, as spec/mailers/previews doesn't exist on heroku instance, you've got a blank page as a result (status 200).
Also note that unlike .gitignore, .slugignore does not support negated ! patterns.
Here is my workaround :
1.move previews away from spec/, to app/mailers/
2.
#environment.rb
...
Rails.application.configure do
config.action_mailer.preview_path = "#{Rails.root}/app/mailers/previews"
end

Related

Pushed to Heroku - Assets(+?) Missing (Rails 5)

I pushed a sample app I was working on to Heroku. Rails 5 - I now notice a lot of issues/differences, a lot I can relate back to an obvious pipeline issue. Majority of the references I see are from R3/R4 but mention putting
config.assets.compile = true
config.assets.digest = true
in and modifying all url to font-url or image-url - I did that for majority of the fonts, but I'm still seeing blank images, and broken links/missing icons.
Another weird thing is I used JSON Builder to builds out a site.json page - The page itself is actually fine; No issues. However, when I try to limit it with a parameter it immediately returns a 500 error. I've found 4-5 other posts on SO about this, each with a minor amount of replies, and usually they say to do what I mentioned above.
I even tried to go into all of my CSS files cores, and change it to
font-url('<%= asset_path("mana.eot?#iefix&v=1.3.0") %>') which also didn't do anything.
I read on Heroku's help site that it has issues due to the MD5 fingerprint and I followed through the steps to connect to the bash to see the file's existance AND the name, but I'm unsure how to really.... do anything about that? Don't they have the same fingerprint when locally compiled/C9/IDE?
In terms of photos missing, you probably have to upload them to AWS or something similar and save the information there. Make an account and follow the instructions, it is pretty straight forward. I had the same problem for my app and that was the solution for me.
In terms of links make sure none of them are localhost:3000 because that will break the links.

Favicon and headers not working in custom domain for rails app with heroku and Godaddy

I have a rails app hosted on heroku and then pointing my custom domain to it via GoDaddy.
I've been struggling to get the favicon to work and have tried everything in this post. Favicon shows up on rails local, not on hosted app
I've also tried rake assets:clobber
I've also tried deleting the favicon, recompiling it, and then pushing. None of this has worked.
Before this I was getting an error about X-frames being from SAMEORIGIN that was causing my site to not render anything in the head as well as not load.
So I added this line to my application controller per another stack overlow answer
before_filter :allow_iframe_requests
def allow_iframe_requests
response.headers.delete('X-Frame-Options')
end
I'm not sure if this is related or not but somehow everthing works on myapp.herokuapp.com but nothing is getting loaded in the head or source in inspector on myapp.com
Here's what it looks like.
As you can see.. nothing is really showing up in the head.
On myapp.herokuapp.com you can see everything that is supposed to be in the head show up.
I'd really like to understand what's going on as this has been super frustrating. I have tried many solutions that I found here but have yet to have anything work. My hypothesis is that it's something to do with Godaddy. Yes I have cleared my cache multiple times.
Thank you for your help!
Perhaps try my site to generate favicons and the correct markup for them:
https://favicongenerator.co
You can upload an icon and it generates all the sizes and the correct markup for rails.

Reverse Proxy with Heroku (for Wordpress) won't show full pages

I am trying to use a reverse proxy to serve a Wordpress blog running on EC2 at /blog from a rails app running on Heroku. I've used the rack-reverse-proxy gem and followed directions like this:
How can I use a subdirectory instead of a subdomain?
My app is running at http://myapp.com, my main target (wordpress) server is running at http://ec2-xx-xx-xx-xx.us-west-2.compute.amazonaws.com.
The pages on the target server all serve up fine when accessed directly. However, no matter what page I try to get through the reverse proxy, the HTML gets cut off. I've tried serving via both my own custom builds of Wordpress on Ubuntu (EC2) and on hosted examples like Bluehost. I've tried to access simple, handmade HTML and text test files, as well as the php files automatically generated by wordpress. Every time, the file is cut off.
Text files just get randomly cut off after ~1000 characters (this is variable)
Ditto for hand-coded HTML files
Wordpress files seem to get cutoff during the <head> (often mid-word) and render an empty <body>.
If a page should exist (e.g. http://ec2-xx-xx-xx-xx.us-west-2.compute.amazonaws.com/test-post, it will load (at least partially) at myapp.com/blog/test-post, so I don't know that rewrites are the issue.
I've tried enough variables on the wordpress/destination server that I'm inclined to think it's something on the Rails side (I have the same issue whether running "myapp" locally or on a Heroku test server). Beyond that, I'm stuck.
Any thoughts as to what I might be doing wrong? There's nothing in the Apache logs to indicate that anything is getting cut off. I'm pounding my head over this to no avail, and would really appreciate any help.
FIXED IT!
Digging into the rack-reverse-proxy gem, I found that I'm not the only person that had an issue with this:
Seeing some issues with Content-Length being corrupted, this ensures it matches body length as delivered.
The fix hasn't been merged into the master branch, but I forked my own copy, applied the fix, and it's working great. Hopefully it'll be merged into the master and nobody else will have to worry about this.
EDIT
One more thing that might be helpful for somebody else, if they are having problems with Visual Editing Mode not working under wordpress: Make sure that you also include this update to have the headers get passed in properly. The gem just hasn't really been updated in a couple of years, so it's up to you to go through and copy in fixes from other people. Applying those two fixes has everything working fine for me with a Heroku app/AWS&Ubuntu Wordpress setup.
Heroku will cut the request after a certain amount of time which would cause the behavior that you're seeing.
You basically have to pull the page from the wordpress blog and reserve it via Rack in the time for one request - think that could be the problem?

Rails get production environment working with SSL on local machin

I am having trouble with my site with precompiled assets looking nothing like my site with assets served on-the-go. So I figured, I should try things out in production.
Here's the problem, when I do, I get:
!! Invalid request
in my terminal log and in my browser I see
Error 107 (net::ERR_SSL_PROTOCOL_ERROR): SSL protocol error.
The graphic designer is not amused at the mess thats up right now, and I'd love to be able to reproduce the problem. Any ideas on how to get past this SSL issue?
The only way that I've ever been able to get sites implementing SSL working on my development box in production mode has been to set up Apache in front of my rails server (Webrick, or whatever). This is kind of a pain to set up, but it works. You should be able to find a guide on how to set it up using your exact configuration with a quick search. Another option would be to enable SSL via a configuration file, instead of by environment, so you could simply disable it regardless of your current environment. This is assuming everything else is actually correct and working...

How to make "assets:precompile" NOT load the database? (Rails)

I'm deploying my Rails app on Heroku (Cedar), and there were 3 options about precompiling my assets I could choose from, and I chose the option where Heroku precompiles my assets on deployment.
When I pushed, I got an error that it cannot access my database (during precompiling). So, how to make Rails not connect to the database during precompiling? I don't know why it's set in the first place, because I can't imagine a scenario where precompiling would need access to the database.
I saw somewhere a solution to disable initializing the application on precompiling, which is achieved by adding the following into the application.rb (setting it in the environments/production.rb doesn't work):
config.assets.initialize_on_precompile = false
I tried adding this line, and it works, but I don't know if it is a good solution. Wouldn't this make some plugins you would potentially use for the assets not load during precompiling, thus affecting the end result?
What you're doing is the correct way. If you don't use models / anything else which is actually accessing the database in your assets then you have no need for it. The only time you'd need to have your app initialized is if you were doing things like this: (Completely contrived example, but you can see what I'm getting at)
/* In some css file */
.some_class{
#{User.find(1).avatar_url}
}
If you enable Heroku Labs (http://devcenter.heroku.com/articles/labs-user-env-compile) you can have access to your Db at deployment time which works great.
Do you use Devise? That's usually a culprit for DB access on precompiling assets incidentally.

Resources