I have a Rails 2.3 application with a custom staging environment I created by putting a staging.rb file in environments/. My staging environment is configured to start the application using that environment. I'm using Bundler to manage gem dependencies as described here, and I have a gem (that I'm pulling directly from git, if that matters) set up to load in the development and staging environments.
When I start the application in the staging environment, it works fine, including the parts that are dependent on that gem. However, when I try to use the Rails console (script/console staging), I get the following error:
<snip>site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- sanitize_email (MissingSourceFile)
It seems like the boot and preinitializer hooks for Bundler are working for the application itself in any environment, but that they're not running properly for the Rails console in the new custom environment.
Any idea what's happening here?
You probably need to execute it in bundler's context:
bundle exec script/console
Related
We recently upgraded webpacker in our project. Now when I deploy with capistrano, I get a compilation error like:
webpack config /path/to/project/releases/20210617155029/config/webpack/.js not found, please run 'bundle exec rails webpacker:install' to install Webpacker with default configs or add the missing config file for your custom environment.
The obvious issue here is that webpacker is not looking for the correct config file, which should be config/webpack/staging.js in this case because I am deploying to the staging environment.
If I try to deploy again after such a failed attempt, it compiles just fine. It is as though whatever webpacker uses to determine the deployment environment is not set until a failed deploy happens. Does anyone know how webpacker determines the rails environment?
I'm working against a variety of constraints that are troubling an EC2 Rails deployment. I'm not allowed to use Capistrano because I cannot save this application to any public git repository (like GitHub) and I also need to retain complete control over which instance on EC2 the Rails application is installed to and be able to modify this easily (adding load balancers, auto-scalers, etc.) on the fly from the AWS Console, so I also cannot use Rubber.
I finally resorted to simply ssh'ing my Rails application directory over to the EC2 instance, but am running into a 'no such file to load' error when running bundle install, specifically the Time gem. Because this is an 'integrated' gem, I think I might just be overlooking something simple. Here are the things that I've tried:
I've used RVM to manage my versions of ruby, rails, rubygems, etc.
Deleting my Gemfile.lock file and re-running bundle-install
Including 'Time' in my GemFile and re-running bundle-install
This application runs without issue on my local development environment, so what am I overlooking?
Note: I am REQUIRED to host on a single EC2 instance. Otherwise, I'd simply deploy to EBS, Heroku, etc.
This was a stupid mistake, also detailed in this question: heroku - cant run rake db:migrate - no such file --Time
I incorrectly had a require statement in a controller for 'Time', instead of 'time'. This was allowed locally, but my ubuntu server ruby environment was not as forgiving. Changing the 'T' to a 't' in my controller and running 'bundle install' resolved this issue completely.
I updated a gem(rtf) in my ruby on rails app through the Gemfile. The app works fine on my localhost but when I pushed changes to heroku and tried 'bundle install' within heroku bash. I see that the gem has been installed based on the log
Using rtf (0.3.3)
Following this, I did a
heroku restart --a myapp
however, when i tried the app on heroku, it still cant recognize the lib installed through the gem, i get the following error(normally appears when the library cannot be reached for command "require 'RTF'").
cannot load such file -- RTF
What am I doing wrong in heroku?
I think you misunderstand how Heroku works. When you run a bash shell on your app, nothing you do on that dyno will affect any other dynos for your app (like your web dynos). Heroku runs bundle install for you when you deploy your app and if your Gemfile is configured correctly all the gems will be installed.
the answer by sevenseacat is right- i had just got the case wrong-
require 'rtf'
works fine. In OSX, it ignores case in the command require 'RTF'
TO SUM UP :
The module PgSearch provided by the Gem pg_search cannot be included, required or loaded on the staging environment (Rbenv, nginx, unicorn,capistrano), the problem happens on the web server through http but does not appear on the staging server's rails command.
An other module provided by an other gem can be included without error.
No problem on the local development environment (rvm, puma).
DETAILS
I am currently developing a Ruby On Rails 4.0 application with ruby 2.0.0 which git repositories are hosted on bitbucket.
I deploy the app through a staging server using capistrano.
Staging server environment : rbenv, nginx and unicorn
Local development environment : rvm and puma
The rails environnment files (environment/production.rb & environment/staging.rb) for both are the same.
WHAT DID I DO :
I have installed the pg_search gem (a PostgreSQL full text search gem) by adding it to my Gemfile and put the clause "include PgSearch" in the Active Record model I wanted to use with pg_search gem
I have run the app in development mode... it works !
PROBLEM :
After having deployed the changes to the staging server :
Through the http server I get this error :
NameError in App::MyController#index
Uninitialized constant MyActiveRecordModel::PgSearch
(Normally, this pg_search gem which is included in the GemFile should have its lib/*.rb files included in the autoload search path and a clause like load "pg_search.rb", require"pg_search" or "include PgSearch" (module included in pg_search.rb file) should pass.
In order to find clues to fix the bug, I have :
-tried if an other module provides by the gem could be included ... It works
After been to the current release path of the staging server I run "bundle exec rails c staging" and tried to :
see if the ActiveRecord Model ( which I included PgSearch) instanciation works.
see if the Module provided by the gem could be found / loaded on the server
and I have executed - include PgSearch and require "pg_search" and load "pg_search.rb".
All these commands were a succeess.
I run out of ideas to find some other clues, would you have any suggestions please ?
Thank you.
Restart the rails server
Gems introduce new code that rails will need to access. To make the new code available to Rails we go through 3 steps:
Change the Gemfile
bundle install
Restart the rails server
When do I need to restart the rails server?
It is easy to forget a step.
We have an application running with Rails 3.0.14 on a server which hosts both staging and production environments (using Debian Linux and Apache 2). Deployment is done using Bundler and Capistrano with the multistage extension. Both environments work fine from Apache Passenger and the production environment is actively used.
However, for some reason since the last deployment our cron scripts stopped working because for some reason the console does not like our production environment any more. No matter what rake or rails command we use, we always get
$ rails c
script/rails:6:in `require': no such file to load -- rails/commands (LoadError)
script/rails:6
bundle install just runs through all gems and says "everything is fine". But compared to the staging environment, I know that some gems are missing in the shared bundle directory (from comparison with the staging environment which works).
How do I force Bundler to reinstall all required gems, even if it assumes everything is fine? It does not seem to have a '--force' switch.
Thanks!
I found the error, but I still don't know how this happened.
It seems the 'railties' gem in the production tree was marked as installed, but the directory it was installed under was half empty (compared to the staging tree). Bundler kept insisting it was installed fine, but half the library files were missing and since 'railties' provides command line and script support, this was exactly what wasn't there.
I still don't understand how Bundler can semi-install a gem this way, but at least I was able to fix the situation by copying the missing files from the staging system.
Thank you for all comments, they helped me look in the right direction.