Ruby, how to set GEM_PATH, for Rails project on hostmonster? - ruby-on-rails

I am new to ruby and having a hard time setting up my gems. Could someone please help me understand how this path works in environment.rb
Some Background Info:
I have my rails app installed on hostmonster and I am trying to run SASS using SHELL. I have no local copy of my app. When I run the SASS command I get -bash: sass: command not found. Which leads me to believe my gem path is wrong. The problem though is that i don't really understand how the path works.
I am confused about this line in particular...
home = File.expand_path("/home/#{ENV['USER']}")
ENV['GEM_PATH'] = "#{home}/ruby/gems:/usr/lib64/ruby/gems/1.8"
NOTE: This is the default path which was set when I installed my Rails app from the Cpanel.
Some things I don't understand...
What is the purpose of the semicolon?
For #{home} , am I suppose to replace that with my
home directory?
Where would usr/lib64 come from? I don't see that directory. I am
assuming I have to create it.
ALSO:
This is what hostmonster tells me to do (which I have done already)...
Using File Manager in your cPanel make a copy of the .bashrc file in
your root directory, name it .bashrc.bak. Now edit the .bashrc file
and add the following to the end of the file:
export GEM_HOME=$HOME/ruby/gems
export GEM_PATH=$GEM_HOME:/usr/lib/ruby/gems/1.8
export GEM_CACHE=$GEM_HOME/cache
export PATH=$PATH:$HOME/ruby/gems/bin
When using a rails application, make sure you add the following to your ./config/environment.rb:
ENV['GEM_PATH']'/path/to/your/home/ruby/gems:/usr/lib/ruby/gems/1.8'
I apologize if this is a "noobish" questions, I have never used Ruby so I am still learning how it all works. I have ruby, rails, and sass all installed. I can run my project in the browser. i just can't get my gems to work. Thanks in advance.

Well apparently the gems I was trying to use were not installed on my server. I thought I had installed them myself when I ran gem install sass. However this didn't work properly because Hostmonster had to give me permission to install gems.
I found that out here...
https://my.hostmonster.com/cgi/help/221
As for the path I had to do the following..
home = File.expand_path("/home/#{ENV['MYCPANELUSERNAME']}")
ENV['GEM_PATH'] = "#{home}/ruby/gems:/usr/lib64/ruby/gems/1.8"
So basically for the path all I had to do was change 'USER' to my cpanel username.
Also note this only works if my .htaccess is set to "production" instead of "development".
Thread on production vs development
And in addition to this I also had a problem with my .htaccess file.
So I had to edit my .htacess file using vi editor. (might be different for other people)
Make sure .htaccess had this content in it
Options -MultiViews
PassengerResolveSymlinksInDocumentRoot on
RailsEnv production RackBaseURI / SetEnv GEM_HOME
/home1/examplec/ruby/gems

Related

RailsEnv misspelled or defined by a module not included in the server configuration

I am following this link http://blog.redpanthers.co/2015/10/how-to-deploy-a-rails-app-with-passenger-and-apache-in-ubuntu-14-04/ in order to install ruby on rails with rvm and passenger. I was fine until I got to configuring my demo.conf file using this command sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/demo.conf. When I tried to change RailsEnv production to RailsEnv dev or RailsEnv development it says that perhaps RailsEnv is misspelled or defined by a module not included in the server configuration. I tried to change this setting because the link says its necessary to be in the development environment in order to see the welcome aboard page. I dont know how to give you a copy of my error log file as I am running ubuntu 14.04 server on vmware and I can't copy out of that. I have pastebinit installed, so if anyone knows how I can copy code from the error.log file to show you why I am getting this error, please advise. Also I would like to know how to configure the acccess control as I am using apache 2.4 and the link im following isnt very clear. I would appreciate any help on this as I am doing it for a college project and I am hitting many walls with completing this installation. please bare in mind I am new to linux.
RailsEnv development AND restarting apache should do the trick:
service apache2 restart

Changing Directory Names in a Rails App

I'm relatively new to Rails as well as using PassengerPhusion. I am running an Ubuntu server on Azure, and have the demo app that Passenger provides working fine. I've even changed the text on the homepage.
My question is this:
In my directory, the file directory's name for the app is passenger-ruby-rails-demo and while I am experimenting, i am changing the name of the directory to something like passenger-ruby-rails-demo-test and it returns an error message when viewing fleetpro.cloudapp.net.
I've tried looking through files trying to figure out how this is routed but haven't had any luck. Is there a file within the Rails installation that is telling Passenger to be inside the specific passenger-ruby-rails-demo directory? Pretty newbish question, but it is really bothering me!
I'm not sure about how the naming convention works in regards to the root directory name of your app "passenger-ruby-rails-demo", but I believe the name of that directory is important to running your Rails app, and might have to do something with the name of the module in your config/application.rb file which is named after your Rails app.
There is a solution though: use gem rename.
Add gem rename to your Gemfile and run bundle install.
Then in your app's root directory, run this:
rails g rename:app_to New-Name
This will basically "clone" the app with your new name. You may have to check to make sure all your config files are present afterwards, but from my experience using it, it was a quick breeze. You will most definitely have to push the new renamed app back to git or Azure.
EDIT
As an example I renamed a Rails app to show what you could expect from the output after running the command:
The Rails app's name isn't the problem, it's the PassengerAppRoot switch you'll be using:
PassengerAppRoot /path/to/your/app
Rails doesn't actually care which folder it's put into, so renaming Rails won't fix your problem.
Renaming Rails only changes the internal class references within your application (things like Rails.application.name which have very subtle implications for your app).
In your Azure server, you'll need to locate either your .htaccess / httpd.conf / nginx.conf file, and change the PassengerAppRoot to your new path. This should resolve the issue.

Rails - Amazon aaws LoadError; .bash_profile snafu

I have been working with the Amazon aaws 0.8.1 gem, with direction from: http://www.jeffreyjason.com/2010/07/12/amazon-product-advertising-api-w-ruby/
First, I installed the gem by adding gem ruby-aaws in my gemfile, then bundle installing and it installed successfully.
Then I added the necessary information outlined in the article to my .amazonrcfile and saved it in my home directory.
Then I tried to run his sample script to make sure everything was ok:
require 'amazon/aws/search'
include Amazon::AWS
include Amazon::AWS::Search
resp = Amazon::AWS.item_search( 'Baby',
{
'Keywords' => 'pants',
'MinimumPrice' => '2500',
'MaximumPrice' => '4999'
} )
items = resp.item_search_response.items.item
items.each { |item| puts item, '' }
And I get the error: 'require': no such file to load — amazon/aws/search (LoadError)
This seems to be a common enough error because he addresses it at the bottom of his tutorial by saying: solution: don’t forget to set RUBYOPT in your .bash_profile via: export RUBYOPT=rubygems
I tried searching for the .bash_profile file and couldn't find it. I made sure hidden files were shown, and still nothing. So I created one and added it into my home directory, but the problem still persists.
Most of the resources online address .bash_profile in Linux or Mac environments, but I am running a windows vista OS (and rails 3.0.7 for further clarity).
Any ideas on how to solve the .bash_profile conundrum and successfully connect to the amazon db's?
Thanks in advance!
.bash_profile is not on window's OS's, so trying to find the .bash_profile is a fool's errand. The real question is how to modify RUBYOPT on a windows system (which it seems the .bash_profile/.bashrc is used for on other OS's).
First, close down your ruby command line if its open, and go to the Start Menu, then the Control Panel -> System ->Advanced Settings/System Properties.
In the Properties section click the Advanced tab and click the environment variables button at the bottom right.
Under Environment Variables, create a new variable with the name "RUBYOPT" and the value "rubygems" then reopen your ruby command line.

How to get a rails 2.3.3 application running on Bluehost with fastcgi

Using Your Ruby Gem(s)
You will need to add /home/username/ruby/gems to the include path.
You can do this by **adding the following code to your script**:
$:.push("/home/username/ruby/gems")
What script are they referring to? This is vague... Where do I add directories to the ruby include path?
Got it. Looks like the gem path for a default bluehost install requires some "massaging" to work. :) Following instructions from here resolved the problem for me (relevant parts cut and pasted below as well):
http://www.bluehosttricks.com
A) You will need to have the ability to install gems locally. You can do this by following these directions (via SSH):
1) Add the following lines to your $HOME/.bashrc file (these can be copy and pasted):
export GEM_HOME=$HOME/ruby/gems
export GEM_PATH=$GEM_HOME:/usr/lib/ruby/gems/1.8
export GEM_CACHE=$GEM_HOME/cache
export PATH=$PATH:$HOME/ruby/gems/bin
2) Now modify the applications environment.rb file so that the correct gem path is included. This line should go up at the top before the version of rails is specified:
ENV['GEM_PATH'] = '/path/to/their/home/ruby/gems:/usr/lib/ruby/gems/1.8'
3) Kill off any fastcgi processes that they might have running and the issue should be fixed.
EDIT:
I ended up having to follow ALL the steps in the tutorial I linked above. You have to manually edit the rack fastcgi handler file or else the dispatcher will complain. Apparently this is specific to Rails 2.3.3 (2.3.2 worked fine on BH (allegedly)).

Setting environment variables for Phusion Passenger applications

I've set up Passenger in development (Mac OS X) and it works flawlessly. The only problem came later: now I have a custom GEM_HOME path and ImageMagick binaries installed in "/usr/local". I can put them in one of the shell rc files that get sourced and this solves the environment variables for processes spawned from the console; but what about Passenger? The same application cannot find my gems when run this way.
I know of two solutions. The first (documented here) is essentially the same as manveru's—set the ENV variable directly in your code.
The second is to create a wrapper around the Ruby interpreter that Passenger uses, and is documented here (look for passenger_with_ruby). The gist is that you create (and point PassengerRuby in your Apache config to) /usr/bin/ruby_with_env, an executable file consisting of:
#!/bin/bash
export ENV_VAR=value
/usr/bin/ruby $*
Both work; the former approach is a little less hackish, I think.
Before you do any requires (especially before requiring rubygems) you can do:
ENV['GEM_HOME'] = '/foo'
This will change the environment variable inside this process.
I found out that if you have root priviledges on computer then you can set necessary environment variables in "envvars" file and apachectl will execute this file before starting Apache.
envvars typically is located in the same directory where apachectl is located - on Mac OS X it is located in /usr/sbin. If you cannot find it then look in the source of apachectl script.
After changing envvars file restart Apache with "apachectl -k restart".
I've run into this issue as well. It appears that Passenger doesn't passthrough values set using the SetEnv apache directive - which is unfortunate.
Perhaps it might be possible to set environment variables in your environment.rb or boot.rb (assuming you're talking about a Rails app; I'm not familiar with Rack but presumably it has similar functionality)

Resources