Rails Dynamically Switching Static Pages - ruby-on-rails

I am running Rails 4 under Nginx and Phusion Passenger on my local machine to develop a web application, everything is setup and running smoothly - there were no problems.
However, when I try to view my home controllers index method, which is a .html.erb file, generated from haml via CodeKit, the page either displays nothing or the current version, and then the previous version of what I have done.
For instance:
Version 1: <h1>Hello, World</h1>
Version 2: <h1>Bye, World</h1>
If I had V1 on the sever, and update it to V2 by simply replacing the file, and refresh the page shows V2. If I refresh again it shows V1. If I refresh again it shows V2 etc…. Worse, if I manually re-type the address the page shows white, nothing, until I restart Nginx.
Is there some weird caching going on… I haven't done anything other than what is outlined in the Rails tutorial: http://guides.rubyonrails.org/getting_started.html#hello-rails-bang
I have touched files up to stage 4.3.
This is a serious problem.

It turns out rack_env was set to production, which enables config.cache_classes, resulting in weird page results and all of this mishap.
Setting rack_env development solves this issue.
Makes sense, since a deployed application won't be having pages constantly changed for .css, content or structure etc….

Related

Rails application crashes on production on index page of all resources upon population of data, but works perfectly on local development environment

I have a rails application that works perfectly on development environment but crashes on index page in production, only when there is a record present on the resource.
When there is no record present, the same index page renders just fine. There are no changes on production.log, weirdly enough, even when navigating through the application.
Keep in mind that just the index page crashes, other areas of the application are still accessible when navigating through the url. Also, the resource's new action is able to save and persist the data.
The production server is set up with puma and nginx. There are also no error on Nginx's log, and access log shows proper redirection of the request to the application.
Nginx's access log:
I have also tried to run the application on local environment in production mode, but it crashes on the first login page.
Upon speculation that i might have messed up on i18n setup, I tried to run the application by first removing i18n from the application and secondly by re-configuring i18, both of which didn't present any changes to the problem.
There are no any complicated calculations on index method of controllers of all three resource.
I am simply returning all the records in an instance variable, that's it.
I am using RoR-6

Dockerized Rails 5 RC1 application not picking up updates to controllers and models in development

I have quite a bit of experience developing Rails 4 apps on Mac OS X + Docker Machine + Docker Compose, but something has changed with how Rails 5 is caching files in the development environment (currently testing with RC1).
After starting the application with docker-compose up, the application runs normally in development mode.
But if I make a change to a controller or model, the only way I can get that reflected in the application is to stop the server and start it back up.
So now my workflow looks something like this when I need to make a change to a controller or model:
Make change to controller/model class.
Stop server with Ctrl + C.
Start server back up with docker-compose up.
Wait on the server to start up.
Run whatever I was running in the browser.
To say the least, needing to do steps 2-4 is annoying and not what I'm accustomed to from Rails 4.
I went a step further and uninstalled Spring using the Removal instructions, but I still get the same behavior.
I also searched for any settings that I could find in config/environments/development.rb related to the Rails runtime's iron grip on the model and controller classes, and I couldn't find anything. (I assume that it really wants to rely on watching the filesystem in order to selectively load changes, and something isn't being picked up from a change on Mac to VirtualBox.)
Any other ideas on what I can try? Or are there any new settings related to how this more aggressive caching works?
I'm Using Rails 5 rc1.
Rails 5 introduced some "improvements" to code reloading, but it doesn’t seem to work with Docker on OS X.
So in config/environments/development.rb, I replaced
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
with
config.file_watcher = ActiveSupport::FileUpdateChecker
It seems that for the ActiveSupport::EventedFileUpdateChecker file watcher, the change event does not occur for docker-machine shared files

Rails host app doesn't see engine layout

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

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?

Solution found: cPanel-created Ruby On Rails setup returns blank pages for any views

Solution found!
This appears to be a bug specific to Mongrel + Rails 2.3.8, the webserver used by Rails+cPanel. This is why it only shows up when you run the app from cPanel, but not when serving it locally via script/server.
For more details, see:
https://rails.lighthouseapp.com/projects/8994/tickets/4690-mongrel-doesnt-work-with-rails-238
The eventual workaround found is to put the following file in the /config/initializers directory of each new Rails 2.3.8 app:
https://gist.github.com/471663
Once I add this initializer, my Rails app functions as expected.
Original question:
I've gone through the very helpful tutorial at railsforzombies.org and am now ready to get a test RoR install going. My site is on a shared host, using cPanel. I've created the test application using cPanel, and it's set up at ~/rails_apps/blog. I created a rewrite that redirects mydomain.com/testblog/ to mydomain.com:12002, which is the port that cPanel has my RoR app running on. I also started the application via cPanel, in development mode.
If I go to mydomain.com/testblog/, I see the helpful page that lets me know that my RoR app has been created and is functioning. Great, right? Well, not so fast.
I'm following along with the Getting Started guide at guides.rubyonrails.org/v2.3.8/getting_started.html, and I get to step 4. I've run script/generate controller home index and edited the resulting view at app/views/home/index.html.erb. It's just a simple
<h1>Hello rails!</h1>
However, when I go to mydomain.com/testblog/home/index (with or without the trailing '/'), I get a blank page in my browser, nothing at all (View Source shows nothing).
To make sure that I'm not going crazy, I put a text file in my rails app's /public directory, and when I go to mydomain.com/testblog/test.txt, it gets served properly. So I know that the Apache rewrite from cPanel is working properly.
Any ideas? I figure I'm overlooking something that's obvious, but I'm drawing a blank for now.
For reference, I'm running on cPanel 11, Ruby 1.8.7 and Rails 2.3.8. I would love to be running Rails 3.0, but the shared host says it's a no-go for now.
edited to add:
Generating the home controller and index action above added the following lines to my routes.rb file (I've checked, they're there):
map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'
so mydomain.com/testblog/home/index should map to app/views/home/index.html.erb.
Edited again with more investigation details:
I found something that may shed some light on this. If I stop the rails app in cPanel, then log in via PuTTY and start the dev server with script/server and execute
curl http://0.0.0.0:3000/home/index
the dev server does respond with
<h1>Hello Rails!</h1>
from app/views/home/index.html.erb. So it's working there. It's when I start the Rails app in cPanel (which tells me its running on port 12002) that I get an empty response from mydomain.com/testblog/home/index. I also get an empty response from
curl http://0.0.0.0:12002
if I run it via SSH on the server. So it looks like something screwy with cPanel, not with Rails.
Did you make sure and delete your index.html file in the app/public directory of your app?
Also, after generating the home controller, did you setup your routes.rb to recognize the new controller and action?

Resources