Deploying Rails App, NameError: uninitialized constant Foundation::Rails::Generators - ruby-on-rails

I'm trying to deploy my first Rails app to my test server. Using Ubuntu, Capistrano, Passenger, Apache. Rails 4.1.9, Ruby 2.0.0.
Everything seems to pull from Github to my production server okay, but rack returns: NameError: uninitialized constant Foundation::Rails::Generators when
try to run rake.
Sorry to be such a N00b but I haven't been able to find the problem.
Error generates from Bundler.require(*Rails.groups) in application.rb
Can anyone point me in the right direction?
Thanks.

Your deployment probably does not run bundle install to install the gems your app needs.
Try adding require 'bundler/capistrano' to the top of your deploy.rb to automatically install the gems in your Gemfile.
Capo.io is a good source when you want to get started with good capistrano recepies btw.

Related

Rails Ruby Geometry Gem breaking in production

running Geometry::Point.new(1,1) in development goes fine meanwhile in my production server it gives uninitialized constant MyControllerController::Geometry
on my production server, I've checked this:
bundle exec bundle show geometry returns
/path_to_app/shared/bundle/ruby/2.0.0/gems/geometry-6.2
bundle exec bundle show ruby-geometry got
/path_to_app/shared/bundle/ruby/2.0.0/gems/ruby-geometry-0.0.5
in dev , even Point(1,1) works , with no need of module and 'new', which breaks in production too. returning: NameError: uninitialized constant Point
I've tried require 'geometry' and include Geometry, but both till fails
can someone help me plz?
Make sure you you put ruby-geometry gem into your Gemfile like this:
gem 'ruby-geometry', require: 'geometry'
I probably should emphasize it even more in README file of the gem.
After 2 days trying to solve this problem the answer was in reboot the machine... reset only the nginx and unicorn do not worked... but when I do reboot the VPS, it started working ...
How did we find out?
Searching about we have run into Pow not loading gem properly while rails s works
I'm Using Ubuntu with nginx and unicorn, nothing to see with Pow ... whatever it gave some light... for no reason we decided reboot the VPS ... and it worked.
Thank you all who helped me

Paperclip in Production with Unicorn: uninitialized constant Paperclip (NameError)

I added Paperclip to my app then tried to deploy to my VPS using capistrano. The deploy happens successfully, but when I try to access my app on the VPS, I get the Rails Error Page.
There is no information in production.log, but unicorn.log has the following error:
E, [2013-06-25T19:44:07.372060 #21995] ERROR -- : uninitialized constant Paperclip (NameError)
/home/deployer/apps/arcsite/releases/20130625182331/config/initializers/paperclip.rb:1:in `<top (required)>'
The initializer file is paperclip.rb and has these contents:
Paperclip.interpolates :zone do |attachment, style|
attachment.instance.zone_id
end
It's an interpolater to allow me to use the folder structure I want.
If I remove the paperclip.rb initializer file, I get an error that has_attachment is undefined in my class, making it seem like the paperclip gem isn't being properly loaded.
I tried to uninstall/reinstall the gem, but when I ran gem uninstall paperclip, it told me that the paperclip gem was not installed. When I ran bundle show paperclip it did show a directory (I'm using RVM), so I manually installed the paperclip gem with gem install paperclip. I'm still getting the same error.
This app works fine in development on the thin server.
My VPS setup:
nginx
unicorn
rvm
capistrano
rails version: 3.2.13
paperclip version: 3.4.2
I followed Ryan's screencast to set up nginx/unicorn
Turns out it was some weird installation behavior. Had to work with the RVM people and have updated the rvm capistrano documentation to reflect the new procedures.
So the problem was that unicorn wasn't recognizing my newly installed gems, all I had to do was simply manually stop and then manually start unicorn and everything got taken care of. I had this exact same issue after deploying my app with paperclip installed.
In the application's root directory through SSH--
service unicorn_"app name" stop
followed by
service unicorn_"app name" start

running rake fails with Gem::GemNotFoundException ERR

Backstory:
New to rails and attempting to install Passenger on a Mediatemple DV server. I am following and somewhat modifying this CentOS guide here since MT currently does not have any recommended 'how tos' regarding setting up a Rails production environment http://www.freshblurbs.com/installing-ruby-rails-3-centos-nginx.
I have fresh-ly installed gem and then ran gem install rake as root. Now, anytime I try to run
rake some_task
I get the following error
/usr/local/lib/ruby/site_ruby/1.9.1/rubygems.rb:370:in `bin_path':
can't find gem rake ([">= 0"]) with executable rake (Gem::GemNotFoundException)
from /usr/local/bin/rake:19:in `<main>'
rake is installed here /usr/local/bin/rake
$PATH is /usr/kerberos/sbin:/usr/kerberos/bin://sbin://bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/bin:/usr/local/bin:/root/bin:/usr/bin:/usr/local/lib
output of gem which rake is /usr/local/lib/ruby/1.9.1/rake.rb
... and unfortunately that's about all I got up my sleeves. What am I missing that's causing this to bomb?
Thanks in advance!
I have the similar problem with rake, but in ruby 1.9.2.
http://betterlogic.com/roger/2010/11/ruby-1-9-2-rake-woe/
Maybe in your case it will be helpful too.
Not sure this'll help maybe it will.. maybe not..
But run a gem list first and make sure both rake and also the passenger gem show up. I think I remember seeing a similar error that was misleading trying to setup a production server recently when running:
passenger-install-apache2-module
face palmed when I realised i hadn't installed the passenger gem yet

Paperclip as a gem and Phusion Passenger (mod_rails) - can't find Paperclip

I'm using paperclip by thoughtbot for attachments to models and everything works fine on my development machine running mac os x and mongrel. However when I deploy may app to a debian machine running apache/mod_rails (2.2.5) I can't get it started. I get 'undefined method has_attached_file' (or 'uninitialized constant Paperclip' using an initializer). I'm sure there is an easy solution but I appear to be blind... Any hints? Thanks!
I would suggest just 'vendoring' your gems. Just require the gems you use in your environment.rb file using config.gem syntax (you can search online for more specific instructions) and then once those entries are in there, just run 'rake gems:unpack' and the gems you have installed that are required for the app (via the config.gem entries) will be put in vendor/gems.
This way your app will always know where to find your gems...
Make sure you have this gem properly installed on target machine. If you used REE when installing Passenger then you need to install gems with gem-e instead of gem. In short:
sudo gem-e install paperclip
Blind was right! I finally solved the issue by specifying the paperclip gem thru the proper config.gem entry in environment.rb. I maintain two different environment.rb files, one for development, the other for the production server and I forgot to add the paperclip config.gem line to the latter... Too bad, sorry for bothering you and thanks heaps for answering! Cheers!

Deploy a Rails app on Dreamhost

I am trying to deploy my first Rails app. I copied all files to ~/mysite.com and set up MySql.
Here's my configuration at Dreamhost.
Now when I visit mysite.com I get a 404 error (which isn't my custom 404 error). It seems that Passenger does not run!
What should I do? Do I need to start Passenger? (touch tmp/restart.txt does nothing)
Based on your stack trace at http://www.foto-fiori.com/ it looks like there's a gem missing on your production server. Check the gem list in your environment.rb config file and ensure all gems are installed. You can also ssh into your application and run rake gems.
rake gems RAILS_ENV=production
You may want to freeze the gems if Dreamhost does not allow you to install them.
rake rails:freeze:gems
4 things to check first:
You enabled Ruby on Rails Passenger (mod_rails) for the domain name
You point your domain name configuration to the public directory of your application.
Your Rails Version (As of 8/5/2009 Rails is up to 2.3.3 but Dreamhost is at 2.2.2)
All your gem dependencies are available at Dreamhost, in your home folder, or are unpacked in your rails application.
If passenger is giving you an error message then your rails app isn't starting, but passenger will put something in the apache logs.
These are in: ~/logs/domain.name/http/
Usually this is because of the wrong rails version or a missing gem or some other mismatch between the dreamhost environment and your development machine.

Resources