How to update a Rails app and avoid old caching by browsers? - ruby-on-rails

During development of my chess rails app I have encountered a few times where after updating my Rails app on the next visit the Chrome browser was displaying the chessboard mangled and hitting refresh in the browser didn't fix the problem. I had to manually disable cache in Chrome and refresh to fix things. Maybe something about the css for the chessboard div's was screwed up I don't know. Sorry but I don't have a more detailed report of the problem.
If this can happen to me during development, then surely the users of my website will encounter this old caching problem and see a broken site. Does anyone have an idea of what was going on and how to prevent this?

In Rails 3.2, asset pipeline takes care of caching for your CSS and JS.
http://guides.rubyonrails.org/asset_pipeline.html
Take a look at the above link to check it out. If you are not using Rails 3.2 use some kind of fingerprinting technique undo the caching.

Related

Ruby on Rails link generated with link_to helper no longer works in Chrome

Chrome has been making a lot of changes recently, and one of them has broken a code statement I use to retrieve a document stored in a database, related to a parent record. The action to upload the file and create the attachment relationship is working, so my users can still add documents. They can no longer download and view stored document attachments. The code is using the link_to helper method, and appears to be building the link correctly, verified by the fact that it still works using Edge, so my users have an ugly workaround, but I need to understand what is happening. I have confirmed that it is indeed Chrome that is the problem, because at first I couldn't recreate the defect in development (until I updated my Chrome browser to current version.) Now I can recreate the defect in my development environment.
When the link in my form is clicked, Chrome displays an error screen with this text:
This page isn't working
(*localhost*) sent an invalid response
net::ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION
If I extract the link using developer tools and try and execute it in an empty browser window, I get the same error.
The link is constructed like this:
(*name of the file attachment*)
Before you ask, yes, I have confirmed there are no commas or quotes in my file names! lol
I am hoping someone somewhere can point me to a solution, hopefully simple, maybe obvious, that I can use to get my web form to play nicely with Chrome again - application code change, web server configuration (I am running on RHEL7 Apache in production and Puma in development, my database is Oracle, and I am building with Ruby 2.3.6 and Rails 5.1.5, along with many many gems).
I hope I have covered all the relevant points. Thank you for taking the time to read this post!
Issue has been resolved by upgrading gem attach to version >= 1.0.5. Many thanks to the gem author for excellent responsiveness.

Rails newbie trying to understand why deployed Rails site has messed up formatting

As a way of learning how to develop with Rails, I have cloned a rails app here
https://github.com/boxerab/redis-io
and have deployed to Heroku:
https://gigacrunch.herokuapp.com/
The original site is hosted here: http://redis.io/
When comparing the two sites, the page formatting seems messed up
for my Heroku hosted site.
Being a beginner, I am not sure how to start investigating why the formatting would be so different if the Rails code is the same.
Any guidance here would be very much appreciated.
Thanks!
So it is clearly a problem with your assets, your css/js. If you use your devtools (chrome inspect element) on the page and look at the sources tab, it will show that the css file (http://polar-wave-5104.herokuapp.com/styles.css?1449091320 ) isn't loading. I don't know why, without more information, but that should be a place to start exploring.

Cookies not saving

I'm working on an application in localhost:3000 and I just started working with cookies and can't get them to stay saved after I quit out of chrome. I checked my preferences and they were fine, cookies from other websites like stackoverflow are being retained. I've tried multiple ways of saving the cookies including
cookies.permanent[:guest_user_id] = create_guest_user.id
and it's not working (create_guest_user is a method for implementing a guest_user, taken from https://github.com/plataformatec/devise/wiki/How-To:-Create-a-guest-user). Also, Devise isn't saving anything either when I check remember me at the login page. I even added
Devise::TRUE_VALUES << ["on"]
as was recommended by another post and that didn't work for me either. I'm using rails 3.1.1, formtastic 2.0.2, and devise 1.5.1. I'm running Mac OS 10.6.8 and chrome 15.0.874.121. Thanks for the help.
UPDATE: I even tried changing my hosts file as was recommended here Can I use localhost as the domain when setting an HTTP cookie? and it still isn't working. Am I missing something obvious?
I guess there just isn't a relatively easy way of solving this problem in chrome. I tried out a bunch of solutions from various sources with little success. Not sure why google has this design in chrome as its developer tools are great and I'm reluctant to switch browsers.

My Rails Application doesn't update the localized strings in production mode

I have a standard Rails application running with the I18n support. I have extensive caching running for this app. I edited a few strings and confirmed it worked locally. I also confirmed I have the right strings on the file for the live site. Still for some weird reason I do not see these changes for my live site even though I have not fragment cached anything here.
Any ideas what is going on?
Another one with the same problem as me :)
I ended up with this solution:
http://szeryf.wordpress.com/2008/02/02/multilingual-page-caching-in-ruby-on-rails/
I couldn't change the structure to include the language identifier in the URL as suggested here:
http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/341bba9357bfc608
Depending on your structure and how fare you are down development, choose either one. However, it's probably easier if you have the cache either as part of your domain or your url.
I hope multilingual caching will be improved in future rails versions.

How can I prevent cache/cookies from affecting the path of ckeditor javascript files in a production rails app?

I have a built a rails app in which I am using the ckeditor 3.5.1 together with the ckeditor gem.
When running in development, everything works fine. But when I run in production, I get errors.Sometimes, the text_area with the ckeditor does not show up. But when I clear my cache and cookies, everything works fine. Then after a while, the error comes up again. The error comes up more often than not.
Closer investigation reveals that when the error occurs, some files like staging.domain.com/javascripts/ckeditor/config.js are instead being requested from staging.domain.com/posts/config.js which is naturally non-existent
(posts is from my Post model)
How can the cache/cookies affect which path the files are served from?
Does anyone know what else might be wrong and how I can fix it?
P.S. I am using Phusion passenger in production.
It would seem the problem was being cased by mod_pagespeed which was activated. By disabling it, everything came back to normal.
I am curious though, about how this was happening.

Resources