When I try to deploy my rails app to my shared hosting (dreamhost) I get this error:
can't activate rack (~> 1.0.1, runtime) for [], already activated rack-1.0.0 for []
So I want to freeze the rack gem in my dev environment, and add it to the project, but even though I have this in my config/environment.rb:
config.gem 'rack'
Doing a rake gems:unpack:dependencies doesn't freeze the gem.
ajmbp:trunk ajl$ rake gems:unpack:dependencies
(in /Users/ajl/dev/site/trunk)
ajmbp:trunk ajl$ ll vendor/gems/
.svn/ haml-2.2.14/ net-ssh-2.0.16/
I tried adding another gem to the config.gem just to test (RedCloth) and that does work as expected, but no luck with rack.
Any ideas?
Thanks!
Have you checked your environment variables (RUBY_GEMS I think it is, or something like that)?
Also, your environment.rb and (if you use fastcgi) your .fcgi.
Make sure the paths are ordered from highest priority to lowest.
See this article.
Any gem that is loaded in your Rakefile (e.g. metric_fu, vlad, etc) is considered to be a ‘framework gem’ by Rails, and such gems are not unpacked. Given that the vendor/gems directory is not yet in the load path when the Rakefile is loading, this is probably a good idea.
In other words, if you have a library that provides Rake tasks, or is otherwise necessary for your .rake files to be valid, don’t expect “config.gem” and friends to handle it for you.
For Dreamhost see their own documentation on installing your own gems. Or see this excellent article on how to load your own packages and gems (be warned it's not for the faint of heart).
But all my reading is telling me that you may still run into trouble because of the way Passenger may be using the Rack version installed by Dreamhost.
Good Luck.
Related
I have a rails-application (rails 5.2) with opal (0.11.1) running.
I would like to use erb-templates on client site. I followed the steps described in the official opal-docs (http://opalrb.com/docs/guides/v0.11.1/templates.html), but requiring the opalerb-file fails. sprocket claims the file could not be found:
couldn't find file 'views/user' with type 'application/javascript'
File views/user.opalerb exists.
It seems that sprockets does not handle / recognize opalerb-files, although I don't find a hint that things have to be configured.
How can I make opal with sprockets find and compile this file?
I ran into the same problem (Rails 5.2.2, Opal 0.11.4). The "opalerb" extension was not being correctly registered with Tilt and Sprockets. I addressed this locally by creating a file called "opal.rb" in config/initializers with one line:
require 'opal/sprockets/erb'
Alternatively, I was also able to fix the problem by explicitly including "opal-sprockets" in my Gemfile, pulling directly from the master branch in Github:
gem 'opal-sprockets', git: 'https://github.com/opal/opal-sprockets.git'
The final option seems to be to include "opal-haml" (even if you don't intend to use HAML). This seems to trigger initialization, although I haven't investigated why.
gem 'opal-haml'
Here's the situation. I work on a large Rails 3.2.13 app (Ruby 1.9.3, Bundler 1.3.5). We've recently begun the process of making this app less monolithic by breaking some components out into gems/engines. However, we have kept the source code in the same git repository. So we've got a file structure like:
APPNAME
|-app
|-gems
|---engine1
|---engine2
|-lib
etc.
Then the Gemfile looks like:
gem 'engine1', :path => File.expand_path('../gems/engine1', __FILE__)
gem 'engine2', :path => File.expand_path('../gems/engine1', __FILE__)
So far so good. My problem is that Gemfile.lock is no longer consistent between developers. Whenever I fetch changes from source control and run rspec or rails server or whatever, I get a modified Gemfile.lock where the diff looks like:
PATH
- remote: /Users/OTHER_DEVELOPER/PATH_TO_APP_SOURCE/gems/engine1
+ remote: /Users/ME/APPNAME/gems/engine1
We've always followed what we considered to be the best practice of checking our Gemfile.lock into source control, but now that's causing git headaches. Has anyone dealt with this problem before? Any ideas for a solution?
The problem here is that you're using gems in an unintended way. They are gems, not DLLs.
If you want a gem approach, host them on a private server and refer to that server in your GEMFILE.
If you want a DLL-like approach in ruby, just use a folder for each library.
Ruby is so darn mysterious when it comes to using the gems! Where do these gems reside?? In java, you can have as many jars you want just include them in your CLASSPATH and your good to go. Ruby is a simpler language, but why do I need the headache of dealing with simple crap? Can anyone seriously finally explain how the gem loading process works? It seems like no one really knows why the heck do requiring some gems work, and requiring others doesn't even if you have gem installed them and they are in the gem list. Where is the authority in ruby on this site that can finally clarify the gem loading process.
I am tried of including 'rubygems' in my ruby scripts to prevent errors like LoadError: no such file to load -- pony
And even when I do require 'rubygems' in my scripts, it still gives LoadErrors. Even if the gem is in my gem list.
When you're using Bundler to manage Gems in your project (you will have a Gemfile at the root directory of the project), be sure to run
bundle install
requiring rubygems just loads rubygems itself (and isn't required in ruby 1.9 and above)
You need to actually load each gem individually via require.
If you use bundler, then you can optionally have bundle auto require everything from your Gemfile
I have the following gems defined in my environment.rb file:
config.gem "authlogic"
config.gem "paperclip"
config.gem "pauldix-feedzirra", :lib => "feedzirra", :source => "http://gems.github.com"
config.gem 'whenever', :lib => false, :source => 'http://gemcutter.org/'
I have them installed on my local computer and everything is working well.
Since I am working on a shared-server (DreamHost), I need to unpack those gems to get them to work (can't install them as I did on my own computer to get them to work).
Before uploading, I ran the following on my local machine:
rake gems:unpack
This created the following folders in /vender/gems:
authlogic-2.1.3, paperclip-2.3.1.1, pauldix-feedzirra-0.0.18, whenever-0.4.1
So it looks like they're all there.
When I run rake db:migrate on the server, though, I get these following error:
Missing these required gems:
pauldix-feedzirra
For some reason, the feedzirra unpacked gem is not detected. Could anybody offer a clue as to why this is happening and a potential solution?
Thanks!
EDIT: Thanks, but the code to put in environment.rb doesn't work, and bundler won't install properly on my server. Any other suggestions?
This isn't exactly an answer, but since I could never get config.gem to work properly, I recommend using Bundler whenever I can. It just works and it handles interdependencies between gems well. It also replaces config.gem in Rails 3 from what I understand.
I notice two things about feedzirra: first, it depends on 3 other gems, and at least one of those build native extensions. And I'm going to call it "feedzirra" - I'm not a fan of github's ill-considered autopackaging fiasco.
If it were only the former, then rake gems:unpack:dependencies would do the trick.
However, at least curb (which feedzirra depends on) is building extensions, and those can't simply be unpacked. You could either get Dreamhost to install them (good luck) or install them into your user's local gem directory.
To do that, you'll need to update your .gemrc and be sure that it includes a line like:
:user_install: true
Then rake gems:install
Unless your deployment environment won't let you build executables, in which case you'll need to shell out for a less restricted package - I know for a fact that Dreamhost does provide packages that will allow for extension-gems.
(And there's the separate issue of libcurl being deployed...)
Try Following.put this code in envoirment.rb
config.load_paths += Dir["#{RAILS_ROOT}/vendor/gems/**"].map do |dir|
File.directory?(lib = "#{dir}/lib") ? lib : dir
end
Don't know if my hints are useful, because feedzirra is compiled extension (against CURL i think). Better solution is to normally install feedzirra gem (it will compile itself) on your server.
You have not installed (unpacked) feedzirra gem, but pauldix-feedzirra. Probably you need feedzirra unpacked too.
Try to add
config.gem feedzirra
into environment.rb and run locally
rake gems:install
rake gems:unpack
It looks like feedzirra unpacked gem is missing in /vendor/plugins. Look if feedzirra will be copied there after those commands...
In my rails application I once used authlogic-oid and ruby-openid. Now I want to get rid of them and I removed both gems and also their config.gem lines from my environment.rb.
Although my application works, I can't do any database migrations because I get a "Missing these required gems" error. Also if I run rake gems:install these gems are re-installed.
Where are the references to the gems stored?
The standard way to define a gem dependency is in the environment configuration. It usually takes place in the environment.rb file for any environment, but some gems might be specified also per-environment. Check the environment files in config/environments.
Also make sure some file doesn't include the gem with the classic RubyGems gem command.
Finally, check these gems are not required by other gems or plugins used by your application.