Rails - Amazon aaws LoadError; .bash_profile snafu - ruby-on-rails

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.

Related

Rails 4.0 receiving emails - no such file (runner)

Up until now I've been using script/runner to forward bouncebacks to eblast-bounceback#mydomain.com and eblast-bounceback#dev.mydomain.com. However it is no longer working in Rails 4.0. I also can't seem to find a good resource online to illustrate how to do it. I usually get directed to the 'whenever' gem - but that's for cron jobs, not for 'piping to programs'.
So this is essentially what I'm currently doing, but is failing:
|/home/user/rails/dev.www/script/rails runner 'EBlast.receive(STDIN.read)' -e development
How do I get this to work? I'm not on Rails 4.1, I'm on 4.0. FWIW I do not have bin/rails. The above command yields "no such file or directory".
There were actually a few things I needed to do.
The email eblast-bounce#dev.mydomain.com was considered 'unroutable'. At first I figured it was because there wasn't any MX records for the subdomain, so I added one. But then I still got the error. I had manually updated the aliases file in /etc/valiases to pipe to the program using a symlinked directory (because I was deploying with Capistrano, and the directory ends up changing after every deploy). Turns out symlinks don't work for some reason when it comes to exim routing (/home/me/rails_deployments/dev.www/current/bin/rails fails). Maybe I'm wrong about the symlinks thing but the problem went away when I used the solution below.
This problem however was solved when I eventually came to another problem (/usr/bin/env: ruby: No such file or directory). I'm using RVM to manage rubies/gems, and apparently the email forwarder didn't know what ruby was. This leads to the final solution:
(when in cPanel, "pipe to program" assumes the user home directory (/home/me/))
.rvm/wrappers/ruby-2.1.0#website/ruby /home/me/rails_deployments/dev.www/current/bin/rails runner 'EBlast.receive(STDIN.read)' -e development
Where ruby-2.1.0 is my current ruby version, and #website is the gemset used by the EBlast.receive code base.
EDIT: Spoke too soon, the command has its own set of problems...(gemfile not present). This is ludicrous.

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

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

Starting script/console for Ruby on Rails with Windows

I'm having trouble starting script/console.
I've tried cd'ing into the project root ("C:\MyProject") then typing "script/console" and I get this:
'script' is not recognized as an internal or external command,
operable program or batch file.
And when I type "ruby script/console" I get this:
Ruby: No such file or directory -- script/console (LoadError)
Any ideas? Should I be running these commands from the root? Thanks.
The usage ruby script/console is present in Rails 2.3.x versions and older. I believe you installed Rails 3.x which deprecated that command.
You need to use now rails console or rails c (short version) from the application directory.
Better pay a visit to the Rails guides for all the other changes.
In Windows you need to use backslash (\) instead of the regular slash (/).
script\console should work for you, provided you use Rails 2.x. On Rails 3 use rails console as mentioned by other coleagues.
Is ruby installed? Is it in your PATH?
http://www.ruby-lang.org/en/downloads/
When it installs, look for the checkbox to add ruby to your path.
If it's already installed, then (on Windows 7), go to the Start Orb, type "path" and click on "Edit the system environment variables". Click on "Environment Variables". In the bottom list scroll down to "Path". Select "Path" and click "Edit". At the end of the "variable value" list put another semi-colon and the path to your ruby.exe.
EG: ";C:\Ruby\bin"
DO NOT delete anything else from that field.

How Can I Load localhost:3000 in Chrome On Issuing A "rails s" Command?

My workflow looks like this:
$>mate .
Edit stuff using textmate
Go to command line to run $>rails s
Go to Chrome to click a bookmark that loads localhost:3000
View the app
Load text mate to fix/revise
Back to command line to git
Repeat
Is it possible to rig step 3 so that it will also load a new tab with localhost:3000 in it? One less click, saved many times.
Since you're using TextMate I'll assume you're on a Mac.
Two things you can do.
Setup Phusion Passenger on Apache (Mac OS X already has apache) so you save yourself the rails s. You can find tutorials on this at many location. But basically you follow the instructions from the Passenger website and then install the Passenger PreferencePane to make your life easier. To do this you'll need the XCode installed.
Start the rails server in the background then calling open to open the URL
#!/bin/bash
#
# save this in script/start.sh
# don't forget to do chmod +x script/start.sh
rails s &
sleep 4
open http://localhost:3000
In addition to the recommendation for Passenger above, I'd also add that you can install the "Passenger Pref Pane" that will let you easily add projects and set their environments (production/development).
Passenger + Passenger Pref Pane will completely eliminate the need for rails -s, with minimal fussing on the Apache config files.
I think Textmate also allows you to do some scripting that might even get you to be able to launch and open the url in Chrome on save, but I haven't ventured into that area of Textmate yet, and it would probably take more work than just hitting refresh after the save.
If you don't mind adding some code, you could put this in your config/application.rb:
config.after_initialize do
if Rails.env == 'development'
system('open /Applications/Google\ Chrome.app http://localhost:3000')
end
end
That will open a new tab each time though and if this is a multi-person project, you may get complaints.
Another option would be to look at live-reload to get the tab to refresh when a file changes. Even without Passenger, on Rails 3 I rarely have to restart the server, so just reloading the tab might make more sense.

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)).

Resources