My Rails 5 application is behaving weirdly. The application is on heroku.
I am using the gem tinymce-rails. Recently, this gem got updated to version 5 which uses new functions. After deployment I faced an issue where one of the plugins (the link plugin) could not be loaded due to using the old syntax.
I am using chrome to open the website. For some reason the tinymce plugins javascript files are not up to date. They also don't have that fingerprinted name with the hash in the end. All other javascript files do however.
I ran heroku run rake assets:precompile; heroku run rake assets:clobber;. It was no good.
I then tried to open the website in incognito mode and found that the tinymce plugins are the up to date ones. Still though without the fingerprinted file names.
How can I force that the old plugin javascript files be invalidated? I will not have control over my users to ask them to clear their caches.
How can I force using the fingerprinted files? I have inspected the heroku server file system and found assets/tinymce/plugins/link
having both fingerprinted and non-fingerprinted files however the non fingerprinted files were the ones used.
I'm having trouble understanding what initialize_on_precompile was used for. What exactly did it mean for it to be false (especially as it relates to Heroku)? What did it mean for it to be true?
Apologies if this question is too broad/vague, but I can't seem to find the answer anywhere.
This option was available till Rails 3.x as when you run rake assets:precompile it initializes the application and tries to connect to the database. So setting this option to false prevents it. So if you have any issues in connection to the database rake assets:precompile won't work and fail this option ensures that it will work.
From Rails Git Repo:
The initialize_on_precompile change tells the precompile task to run without invoking Rails. This is because the precompile task runs in production mode by default, and will attempt to connect to your specified production database. Please note that you cannot have code in pipeline files that relies on Rails resources (such as the database) when compiling locally with this option.
In Rails 4.x this option has been removed and is no longer required. Rails 4 now always loads initializers and the database configuration before precompiling assets
Source of Commit: https://github.com/rails/rails/commit/2d5a6de
So just trying out Rails 3.1-rc1 with the Sprockets asset pipeline:
I run rake assets:precompile
and I get the /public/assets directory and the application.js file the MD5 hash:
application-266b6b0b4fbd28fc01145d90a4158b2f.js
But the problem is this:
When I update my JS and run rake assets:precompile I get more JS files and it doesnt delete the old ones.
I'm note sure how it works - the browser only picks up the first one and I have to manually delete the old ones. Which doesnt seem like how it should work.
Just a side gripe: It seems I have to run rake assets:precompile every time I change something. Which is painful.
(I guess there needs to be some docs on how this all works).
Thanks.
The name of js file is <file name>-<hash>.js.
That's made so that when you deploy new version of application to the production server your visitors would have to load new js file as well. The hash ensures that they will not have mixed up new application and old cached js that may break entire application taking into account dynamic nature of the web this days.
In most deployment scenarios you will have your app in new directory on the server and you will not have old compiled js files there.
I'm working to install Jammit on my Rails 3 app and then to deploy to Heroku.
I installed the Jammit Gem, and configured assets.yml just fine, it works on dev. But when I pushed to heroku, the files were 404'ing.
Jammit's Usage instructions say: "You can easily use Jammit within your Rakefile, and other scripts:
require 'jammit'
Jammit.package!
I'm not following where/how that works. Running Jammit in my sites command like on the Mac yields a command not found.
Any Jammit users able to help me understand how to move to production with Jammit?
Thanks
I'm using jammit on a Rails 3.0.7 app, on Heroku
gem "jammit", :git => "git://github.com/documentcloud/jammit.git"
I have this in a rake file, to package up the assets before I commit/deploy
desc 'jammit'
task :jam => :environment do
require 'jammit'
Jammit.package!
end
And this in .git/hooks/pre-commit so it is done automatically
echo "jamming it"
rake jam
git add public/assets/*
git add public/javascripts/*
By default, the expires time on Heroku was only 12hrs, to increase it (because I have a cache-busting scheme that I am confident in) I put this in config/initializers/heroku.rb
module Heroku
class StaticAssetsMiddleware
def cache_static_asset(reply)
return reply unless can_cache?(reply)
status, headers, response = reply
headers["Expires"] = CGI.rfc1123_date(11.months.from_now)
build_new_reply(status, headers, response)
end
end
end
To decrease the load on my Heroku Rails server, I am also using a free account at CloudFlare which provides a lightweight, reverse-proxy/cdn, with some decent analytics and security features.
When I get around to caching common content, this thing is really gonna scream!
You could, as I do, use jammit force to pack your assets, upload everything to s3 and define an asset host(s) in rails. This has the added advantage of keeping your slug smaller and more responsive as you can add your public directory to .slugignore .
Alternatively you'll need to work out how to make the heroku version work due to the read only file system.
You can also use a git pre-commit hook to ensure your assets are packaged prior to pushing to heroku (or any server). See https://gist.github.com/862102 for an example. You can copy that file to .git/hooks/pre-commit in your project directory.
this one is the solution
https://github.com/kylejginavan/heroku_jammit
Heroku has a read-only file system, so Jammit is unable to actually store compressed and minified CSS/JS files.
Here is a very good article on the challenge of asset packaging on heroku: http://jimmycuadra.com/posts/the-challenge-of-asset-packaging-on-heroku
I'm new to Ruby on Rails (PHP developer here) and I need to edit an existing ROR project. I've been using Aptana Studio for my PHP projects (switched to Zend after Aptana 2.0) but I've kept Aptana RadRails for my ruby projects.
So what I want to do is to get the ROR project from the server (it's hosted on some linux machine) and import it into RadRails for local development. I've downloaded the files from the server and imported them in a new RadRails ROR project but it doesn't work as intended. Is there anything else I should do ? I've read about 'freezing the gems', switching to production mode and dumping the database for a ROR project upon releasing. Are there some steps needed to undo those operations ?
UPDATE:
The problem that I'm having is that I get various errors when trying to visualize in the browser the pages for different controllers.
ActionController::InvalidAuthenticityToken in
No :secret given to the #protect_from_forgery call. Set that or use a session store capable of generating its own keys (Cookie Session Store).
OR
no such file to load -- xml
This error occurred while loading the following files:
hotels_pro
xml
This leads me to believe that (maybe) I haven't got all the files. On the other hand I have double-checked and I have all the files from the server.
Thanks,
A RoR application is more than just the sum of its source files. There's also the database, gems and a server which exist outside the project directory. Without knowing exactly what doesn't we can only speculate which is causing you problems. Being new to Rails, it's probably all of them. If after all this you're still not up and running a few rounds of "Google the Error" should fix you up.
You'll need to set these things up in your development environment before you can proceed. The following assumes you have a working ruby environment: rubygems installed with the rails, and rake gems. Note any commands and paths that follow are relative to the root of your rails project.
Database:
Start with editing config/databases.yml to find out which database your app will try to connect to. Change it if necessary so it names a local database. Create that database, if it doesn't exist with $rake db:create
If you need existing data to test with you can take a dump from your production database and import it into your working database. How to do this is dependent on the type of database in question. Otherwise you can run the migrations with $ rake db:migrate to produce your development database (assuming the previous developer designed the database with migrations.)
Gems:
Check the config/environment.rb, for your list of required gems. Install all these gems if they haven't been already.
If you're using Rails 2.1 or newer, you can streamline this process by ensuring that all gems are required using the newer config.gem 'this_gem' form instead of older require 'this_gem' declaration. Once all required gems are in this form, you can use $ rake gems:install && rake gems:build to ensure they're all installed.
Server:
Is pretty trivial, all rails instalations come with web brick which is fine for development. But mongrel is also suitable.
P.S. If you're not using some kind of revision control it's strongly advised to set something up before starting. It's not a requirement, but it will likely save your ass at some point.