Rails : Cannot include PgSearch Module provided by the pg_search Gem - ruby-on-rails

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.

Related

can't get past AWS Elastic Beanstalk "Congratulations" screen when launching Ruby on Rails app

I followed all of the directions and this is the result.
I'm in the process of creating the .rvmrc file at my application root path, as well as the setup_load_paths.rb file in my /config folder as described here. I did all that, and then I realized my computer is using ruby 1.9.3p194. While the EC instances is using 1.9.3p286. So I'm in the process of matching them up and re-creating the .rvmrc file.
While doing that, I noticed that the beanstalk ec2 server doesn't even have rails installed. I should be able to type rails --version I assume and see the version like I can on my computer and with ruby --version on the server. So I'm installing RVM, with and rails (as I've done in the past) on my new beanstalk ec2 server. But in general, it seems this all defeats the purpose. It's supposed to be somewhat automatic. Installing rails definitely doesn't sound right. Was it installed another way on the server?
Any advice on how to get the new beanstalk support for ROR working? What am I doing wrong?
From the error in your passenger exception it looks like Bundler was unable to locate the Ascii85 gem in your remote sources. Your remote source should be listed in your Gemfile at the top line in the form:
source :rubygems
If this is not working, try specifying the source explicitly in the form:
source 'http://rubygems.org'
Note that you should not be doing anything special for RVM/Passenger integration in a deploy. In fact, any extra specialized integration may actually cause problems with Elastic Beanstalk if any platform details change. You should be building your application using standard Rails conventions.
As far as rails -v failing: Rails is brought in via your Gemfile, which relies on bundle install succeeding. Your passenger error shows that Bundler failed to resolve your dependencies against your remote sources, which likely means that Rails was also not installed. In other words, Rails will only be available if the bundle installation succeeds.

Error while running rails on remote host. "Could not find crack-0.1.8 in any of the sources"

I am trying to deploy my rails app that is working fine on my local machine , to a remote host. I am using railsplayground.com to be exact. When I try to run the app using Passenger,I get this error
"Could not find crack-0.1.8 in any of the sources"
But when I did a,
$gem list
the gem , crack (0.1.8) is present. I am using Rails 3 btw.
Any suggestions is welcome. Thanks in advance.
Make sure the Gem is installed via Bundler. Check your Gemfile and see if the gem is listed.
Then, when deploying the application, make sure to execute the $ bundle install command.
If you deploy the project with capistrano, you can use the default bundler recipe by including the recipe at the top of your deploy.rb file.
require 'bundler/capistrano'

Bundler not loading gems for script/console in custom environment

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

Problem deploying frozen Rails app - "could not find RubyGem rack"

I have a rails app which I develop on Windows with Rails 2.3.5, using sqlite3 as my database engine, and the internal Mongrel server as my webserver.
I deploy this app to a hosted Linux machine running Rails 2.1.0, using Postgres as my database, and Apache (calling dispatch.cgi) as my webserver. I do not have permissions to update the native Ruby or Rails installations, or to install gems natively.
In order to make my deployment easier (I thought...), I have taken a branch of my code-base for the deployed system. On this branch, I have updated database.yml to refer to postgres and run rake rails:freeze:gems and rake gems:unpack:dependencies. I have then exported this branch to my production server.
When I try to view my app on the production server, I get the error:
Application error
Rails application failed to start properly"
Checking the Apache error logs, I see the following:
./../config/../vendor/rails/railties/lib/initializer.rb:271:in `require_frameworks': Could not find RubyGem rack (~> 1.0.1) (RuntimeError)
from ./../config/../vendor/rails/railties/lib/initializer.rb:134:in `process'
from ./../config/../vendor/rails/railties/lib/initializer.rb:113:in `send'
from ./../config/../vendor/rails/railties/lib/initializer.rb:113:in `run'
from ./../config/environment.rb:9
from dispatch.cgi:5:in `require'
from dispatch.cgi:5
I'm confused. If Rack is required, why wasn't it included by gems:unpack? How can I get this working?
(If it's relevant, vendor$ find . -name rack* gives the following:
./rails/railties/lib/rails/rack
./rails/railties/lib/rails/rack.rb
./rails/railties/lib/rails/.svn/text-base/rack.rb.svn-base
./rails/actionpack/test/controller/rack_test.rb
./rails/actionpack/test/controller/.svn/text-base/rack_test.rb.svn-base
./rails/actionpack/lib/action_controller/rack_lint_patch.rb
./rails/actionpack/lib/action_controller/.svn/text-base/rack_lint_patch.rb.svn-base
)
Rack isn't included because it is a framework gem. To vendor this gem you can manually unpack it into vendor/gems like this:
cd vendor/gems; gem unpack rack -v="1.0.1"
You could also start using bundler to manage your dependencies, as Rails now does by default in version three to avoid problems like the one you're currently experiencing.
Your first problem is that Rails 2.1.0 does not use Rack as a middle layer.
You also need to change the rails version in the config/environment.rb file.
Also, depending on the other gems you have used, you may need to go back to a stable version that works with 2.1.0.
Personally, I would install 2.1.0 on my local machine create a new app with that rails version, copy the app folder over from the 2.3.5 project (and of course your unit tests and public folder, etc, and see if you can get it to run under 2.1.0 on your local machine, substituting gems as you go that are failing in the backtrace on the server log or in the browser. This will be much easier than running in production mode and looking at apache logs. Presuming that you have good unit tests that render all your views and flex your model code, then you should flush out any methods you have used that were added since 2.1.0 that are not supported in the older versions of Rails pretty quickly.

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