Rails host app doesn't see engine layout - ruby-on-rails

What I want to do works on my OSX dev machines and on a staging server. However, I encounter problems on the production server.
I have a Rails Engine which I have created, maintained, and used over the years: https://github.com/allesklar/tkh_admin_panel
It works fine on many apps and I have been porting it to this new website as of late. For admin views, my controllers render the 'admin' layout which is located on this engine.
Everything has gone great until I tried to deploy to the site's production server. I get the following error:
ActionView::Template::Error (no implicit conversion of nil into String):
This exception occurs in the line with the following code:
render layout: 'admin'
I can't pinpoint any differences in gems, rbenv ruby versions, or any other factor from one setup to the next.
I've tried to reset the binstubs and done a number of other things.
No matter what I do, it works on the staging server and not on the production server.
Please point me to some directions where I can investigate further.
UPDATE ---
The scope of the problem has changed entirely since now I'm experiencing the same issue on my development machines.
I therefore think the problem lies in the host app/gem relationship. The same version of this gem works fine with some other Rails host sites of mine.
Any ideas welcome.

Try to recompile all assets. If you can (it's a prod server) delete all assets and manifest and re-deploy.
Try to delete all cache, if you are using page or fragment caching, perhaps your deploy system is not cleaning it correctly.
Simply reboot the system (simple action that fixed a lot of problems in the past).
And if nothing works, try to display the full backtrace to see where this is happening

Related

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?

Spree 2.1 deployment on Heroku

I am trying to deploy an ecomm site I am developing to Heroku.
I am using Rails 4, Spree 2.1 with the Spree_Fancy theme overtop that, S3 for images, and postgres as database in all environments.
The application is working perfectly on my local machine, but when I deployed it to Heroku, the front end breaks. The app runs via Heroku, but there is no styling at all, no theme, nothing. Just plain text and "no products found" message.
I expected there to be no images (since none had yet been uploaded to s3), but there were no products either, even though the db migrations ran.
Any ideas of what I am missing?
I've just answered on another thread the same problem scenario. Hope it helps.
Broken spree_fancy layout on heroku

Redmine 404 on some pages

I have installed Redmine on a shared Bluehost account and at first sight it seems to be working.
I followed both of these tutorials: https://my.bluehost.com/cgi/help/redmine and http://www.redmine.org/projects/redmine/wiki/RedmineInstall
But just as i started navigating around i noticed that there seem to be a routing problem because some of the pages are returning a 404 error code for a reason i don't understand yet.
The error log shows no information regarding this problem.
The url is on redmine.example.com , the user/pass are still admin/admin.
I have identified that any URL regarding a project is failing, for example:
http://redmine.example.com/projects/new
http://redmine.example.com/projects/21
http://redmine.example.com/projects/21/issues
(Currently i have reset the DB for privacy concerns)
In order to prove my theory that it was regarding the projects issue, i went into the projects controller file found in app/controllers/projects_controller.rb and tried to put some abort("Foo") here and there but i couldn't see my message with any of the links that are not working so i thought maybe the problem is not there and is probably in the routing process. So i checked the config/routes.rb file and comparing it with my local version they seem identical
I am not sure what to try next as i am not a Ruby developer. Let me know what kind of info you need in order to help debug this problem.
Eventually i got it working by using FastCGI.
In order to do that, i simply created a .htaccess file and a dispatcher.fcgi as shown in the answer here : Redmine 2 on Hostmonster apache fcgi: Rails application failed to start properly
Don't forget to SetEnv GEM_PATH to your ruby gems path in your .htaccess file and it should work after restarting (pkill dispatcher.fcgi)

Memcache working in production but fails locally

I'm working on an app with a friend and I keep running into errors in my local environment but the app works online (using Heroku). I believe memcache is causing issues in my local environment. Here's what I've done so far:
Added the memcache add-on to my app in Heroku
Installed Homebrew on my machine
Installed memcache using Homebrew with brew install memcached
Then I've restarted my app and ran the memcache process with memcached -vv.
When I access the app it works fine. Then I'll create a record. This also works fine. Then on page reload - when the record is fetched from the cache, the entire app systematically fails. Below is the error I receive (although I'm not sure how much help it is)
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.empty?
The error(s) only point to code where memcache is used. A simple user action (i.e. buy a book from a company) triggers the error and once it occurs the entire app is broken (meaning any route leads to the same error). It seems as though its just not storing/fetching the item, which makes me think the app isn't hitting memcache at all...Is it possible I have to gem install something - even though this is working in the production environment and on another dev's machine?
I'm looking for any guidance with troubleshooting memcache. More specifically, has anyone ever run into issues with local vs. production environments in regards to memcache? Any suggestions? I've thought about removing memcache from the app on Heroku, then un-installing it on my computer and then redoing everything.
I know I'm being fairly vague here but I'm not exactly sure what code to post that would help.
Thank you for any help.
After much frustration I began retracing the steps I took to install and implement memcache on my local environment. It didn't make sense how it was working online and with my friend's environment but not mine. Eventually I ran bundle install and then restarted the app and ran a new memcached process and that fixed everything. I'm still a bit confused but I guess my Gemfile just wasn't updated (even though I could've sworn it was).
I use memached without any problems in my environmens, though I do not use Herouku. To access memcached, I have installed the Dalli gem from https://github.com/mperham/dalli
Using it is rather simple.
In the file environment.rb add:
DC = Dalli::Client.new('localhost:11211')
In the application I use
DC.get(key)
DC.delete(key)
DC.set(key,value)
You will first need to test if the keys you're setting are actually getting set or not. You can use Memcached via a Telnet interface to test this.

Rails Routing Error on static single image

I'm getting a rails routing error for a brand new image I just added. The other images in the folder all work perfectly (/public/images/%f requested at /images/%f) yet this one produces a routing error. I've checked file permissions and it's not that.
Anybody know what might cause this? I'm using the development env so caching is off and I've verified it is!
Thanks,
Jay
Ok, rebooting my vagrant VM fixed it. Don't ask me why because I don't know and it doesn't make logistical sense, in the dev env everything should be reloaded on each request.
I did nothing else except boot the VM again after Zachary asked for some fail code and it was accessible as soon as rails loaded. I spoke to a colleague shortly thereafter and he too had a very similar issue where files were not accessible until after a reboot of the machine and similarly rebooting rails itself didn't do the same job for him either.
Sorry for wasting your time!

Resources