Deploying a modified vendor asset to Heroku - ruby-on-rails

I have Jquery-datatables-rails gem installed. When you install the gem via bundle a folder is created under .rvm/gems/RUBY#GEMSET/gems/jquery-datatables-rails
Inside of this folder you can browse to the vendor/assets folder and modify the CSS, etc.
The only problem is that upon deployment a remote version of the gem is installed on the remote production instance, which does not reflect the local changes.
Is there any way to ensure the local modifications are pushed to Heroku?
Thanks

You can fork the gem and point to it on github as you mentioned, or you can make the changes to your local assets directory which will speed up the time it takes to compile your app on Heroku.

Related

Where are Ruby gems located on a server?

My understanding is that the gemfile in a Rails app only provides references to the actual code of these gems on your local computer. So when you're running your app locally, it's pulling the gem code from your local computer. What happens when you deploy though? The server runs your rails code, but does it also hold all the references in your gem file and automatically download them as well?
Yep. If you deploy on Heroku, you can see bundler doing its work and pulling down the gems.
As per the Bundler docs, you can use bundle show --paths to see exactly where your gems are being loaded from.
Additionally, if you aren't using bundler, you can use the command gem environment to see gem paths on the system.
See this existing answer for more info: How can I find where gem files are installed?

Why do I need to "bundle install" before pushing a rails app to heroku?

I suppose the bundling is going to happen on the heroku servers anyway. What is the purpose of doing it on the local machine?
bundle install
This ensures that all gems specified in Gemfile, together with their dependencies, are available for your application. Running bundle install also generates a Gemfile.lock file, which should be added to your git repository. Gemfile.lock ensures that your deployed versions of gems on Heroku match the version installed locally on your development machine.
If the platforms section of your Gemfile contains Windows entries,
such as mswin or mingw, then the Gemfile.lock file will be ignored.
Heroku also uses that file to resolve and install your application dependencies automatically. All you need to do is to push it.
Refer this link : Click Here
This will update your Gemfile.lock, that heroku uses to install all your gems on your virtual server. The Gemfile.lock contains all information about your gems and their respective versions.
It has two purposes :
It ensures you that, on your machine, you have all the dependencies for your application satisfied;
It updates the Gemfile.lock file. While the Gemfile has the list of your app's gems, the Gemfile.lock has a more.. "detailed" version of it, with the gem's own dependencies, their version constraints... It basically is a snapshot of your project dependencies. This way, your app in production will run with the exact same versions of third-party code as do your code in local.
This ensures that all gems specified in Gemfile, together with their dependencies, are available for your application. Running bundle install also generates a Gemfile.lock file, which should be added to your git repository. Gemfile.lock ensures that your deployed versions of gems on Heroku match the version installed locally on your development machine.
Source: https://devcenter.heroku.com/articles/bundler

Rails 3.1 on heroku ckeditor

I have a big problem with the ckeditor "3.7.0.rc2" gem.
In development it works great with s3 a backend for uploading.
But on heroku it does not work.
The problem is that the ckeditor/vendor/skins/(kama) or (office2003) or (v2) /editor.css files contains an error that makes the sass compiler scream. The error like this "filter:;", since there is no value it does not work.
There is no point in change the files locally, because heroku downloads the gem as I deploy.
I have tried to package the gem locally and make my own git fork and install it for there. But, then the
RAILS_ENV=production bundle exec rake assets:precompile
command precompiles all files in the ckeditor folders and always ends in
rake aborted! Permission denied
When I precompile with the "3.7.0.rc2" gem installed, some ckeditor js files are precompiled but not all.
How can I get around this problem?
When you fork ckeditor gem and use the forked git path in Gemfile heroku will pull the sources of ckeditor from your forked git repo instead of the gem. This should fix the issue.
Other thing that you could try is precompile the assets in your development machine and push the assets to heroku. This will make sure that heroku will not precompile those assets. More info is available at http://devcenter.heroku.com/articles/rails31_heroku_cedar. This will run only on cedar stack
The solution was to fork the git repo, delete all unnecesarry and correct the errors. js files. Then the precompiling worked and now the app is running on heroku.
Here's a link to my fork https://github.com/andreaslyngstad/ckeditor
It worked in my project, but I have deleted js files that I did not use, so if you are using some of them, this is not for you.

Using Hunspell With Heroku

I'm building a Rails app that uses Hunspell and the hunspell-ffi gem so that Ruby can interface with it. I'm deploying the app to heroku, but unfortunately it needs Hunspell to be installed on the server in order for the gem to work.
Is there any way for me to install Hunspell on Heroku? Or am I going to have to migrate to EC2?
Thanks in advance :)
You need to build the required Hunspell library and include it in your Heroku project directly.
Heroku runs on 64-bit Ubuntu therefore the binary has to be compiled under that system. The best approach is to simply use Heroku's Vulcan build server to compile on a Heroku instance.
Compiling for Heroku
gem install vulcan
vulcan create vulcan-compile-me last argument is your own app name.
Download Hunspell source
Extract
vulcan build -v -s ./hunspell-1.3.2 Tells Vulcan to build it and downloads the finished product automatically to /tmp/hunspell..
The build server requires the cloudant add-on, this is installed automatically but you have to make sure to have a verified (credit card added) Heroku account. If you get errors in step six of no build output then do heroku addons:add cloudant --app vulcan-compile-me
Adding to Your Project
Extract the Heroku Vulcan build tar from /tmp
Copy the entire lib folder to vendor/hunspell in your project root directory
Tell Heroku where to look for libraries: heroku config:add LD_LIBRARY_PATH=vendor/hunspell/lib.
Install Dictionaries
Download some dictionaries from Open Office and add them to your project. A good location is a folder called dictionaries at root level. This path is then referenced when initializing Hunspell in Ruby.
http://extensions.services.openoffice.org/dictionary
ftp://sunsite.informatik.rwth-aachen.de/pub/mirror/OpenOffice/contrib/
Using
Install your favorite Hunspell gem, I use hunspell-ffi. There is a newer gem for Hunspell but I prefer the previous FFI gem. To use initialize the Hunspell object with your dictionaries folder path and language (language match the dictionary file name).
dict = Hunspell.new("dictionaries", "en_US")
if dict.check('caribean') == false
suggestions = dict.suggest('caribean')
if (suggestions.size)
correction = suggestions.first # returns 'caribbean'
end
end
Vendoring for More Complex Projects
You can also vendor the library into your project by putting the tar built by the Vulcan server in the first step into a public accessible server such as Google Storage and then changing the Heroku build pack to download the tar on each instance startup.
heroku config:set BUILDPACK_URL=https://github.com/peterkeen/heroku-buildpack-vendorbinaries.git
The vendor build pack looks for a .vendor_urls file at the root level with HTTP links to the tar balls to install (needs to end in a new line to work).
http://commondatastorage.googleapis.com/developer.you.com/hunspell-heroku-1.3.tgz
Vendoring unpacks the tar into the root folder so the lib path for the Heroku settings would then just be "lib". heroku config:add LD_LIBRARY_PATH=lib
Unless I am mistaken or something has changed (I cannot find any evidence of this), you cannot install external native libraries on Heroku. If the library is not already installed (this is the case, I think, for ImageMagick, and perhaps others), you will not be able to use the gem.
Checkout this url: http://gems-summary.heroku.com/2011-07-19
It's freaking amazing how much support Heroku has for the gem community. So all you need to to is add the gem to your bundle since Hunspell is on rubygems, bundle install, and then deploy.
Gemfile
source 'http://rubygems.org'
gem 'rails', '3.0.5'
gem 'hunspell'
Then add to git:
git add .
git commit -m 'added hunspell'
Then bundle:
bundle
And deploy:
git push heroku
With Bundler, you should be able to install any gem. According to http://devcenter.heroku.com/articles/how-do-i-install-gems-for-my-app, "Almost any gem - even those with native dependencies - can be installed using Bundler. If there’s a specific gem that won’t install on Heroku, please submit a support ticket."
AFAIK, when your app is spun up, gems in the Gemfile are installed on-the-fly to the server your app is spun up to.
The Aspen stack has pre-installed gems, but you still should be able to add gems not pre-installed.
The bamboo stack has no pre-installed gems, so all gem dependencies must be declared explicitly. I believe that is the same for the Celadon stack.

How to create a gem repository

I'm trying to deploy my local app to dreamhost using Capistrano. While running the cap deploy:cold for the first time, I'm getting an error for missing gems. The dreamhost wiki also recommends that users should maintain their own gem repository in the folder $HOME/.gems .
Going back to the main question :
Where are the .gem files stored locally? I can find the individual gem folders in /Library/Ruby/Gems/1.8/gems/ (on my mac). But I cannot find the respective .gem files.
Would copying these .gem files to the server at the location $HOME/.gems/gems solve the problem of missing gems?
Is there a better way to avoid this?
All you need to do is put your gems in a folder and point your app to that; however, this is obsolete. Bundler what what you should use. Below is an article on how it works with DH:
http://wiki.dreamhost.com/Bundler#Get_Your_App_Using_Bundler

Resources