Paperclip with Passenger

1) be sure to put in your environment file (inside your initializer)

config.gem “paperclip”

2) make sure your form_form has multipart set to true like this:

<% form_for @photo, :html => { :multipart => true } do |f| %>

3) if using passenger, you must put this in config/initializers/paperclip.rb:

if RAILS_ENV == “development”
Paperclip.options[:image_magick_path] = ‘/opt/local/bin/’
end

(Make sure your imagemagick binaries are really in /opt/local/bin/. You can type /opt/local/bin/convert -v to check. I would recommend the MacPorts installation of ImageMagick and re-install if you are unsure.)

4) If you’re having trouble getting it to generate thumbnails, try setting Paperclip.options[:log_commands] = true and see what it’s trying to run.

With Passenger where does the console log (output from puts) go?

When running Passenger (module for running Rails on Apache), the console log (output from puts) goes into the apache error log (see /var/log/apache2/error_log)

Categories
Programming

Passenger with Rails

Passenger is a great thing because it makes Rails apps able to be deployed on Apache.

The installation is pretty painless, but there are a few gotchas you may want to know about.

Start here: http://www.modrails.com/install.html

sudo gem install passenger

The installation will prompt you to add this to your httpd.conf file: (note the version number of passenger might be different)

LoadModule passenger_module /Library/Ruby/Gems/1.8/gems/passenger-2.1.3/ext/apache2/mod_passenger.so
PassengerRoot /Library/Ruby/Gems/1.8/gems/passenger-2.1.3
PassengerRuby /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby

If you are NOT using the Passenger preference pane, follow these instructions to add a virtual host to your Apache configuration file, and set its DocumentRoot to /somewhere/public. If you ARE using the passenger preference pane, you don’t need to do this.


RailsEnv development
ServerName mysite.local
DocumentRoot /Users/jason/DEVELOPMENT/mysite/public

Options FollowSymLinks
Order allow,deny
Allow from all

======================================================
SOME COMMON PROBLEMS
======================================================
SYMPTOM:
When first installing passenger (sudo gem install passenger), I get this error:
Building native extentions. This could take a while…
ERROR: Error installing passenger:
ERROR: Failed to build gem native extensions

FIX: Type ‘make’ at the command prompt. If you get the error “make: command not found,” then you don’t have ‘make’ (gcc compiler) installed, so your system can’t build anything. Install XCode Tools to solve this.

======================================================
SYMPTOM: Site loads but it does not go to your rails app correctly.

FIX: Check to make sure apache config file, or the file you included in apache config, is correct. Try putting your site at a different port like this:

Listen 8000

Remember to restart apache each time you make a change with:
sudo apachectl restart

======================================================
SYMTPOM: Browser says “500 Internal Server Error”

FIX: Check the Apache error log (Applications > Utilities > Console, click “Show Log List” if the list of logs does not appear, go to /var/log/apache2/error_log )

======================================================
SYMPTOM: *** Passenger ERROR:Could not spawn the sever the server… Permission denied

FIX: If you are running a custom ruby executable (see custom ruby executable with passenger), you may not have set your custo ruby executable file to have execute permissions.

======================================================
SYMPTOM: Routing error … no route for /YourApp

FIX: If you see this in your browser (where /YourApp is the name of your app), it is probably because you did not have this in your Rails config/environment.rb file:

Rails::Initializer.run do |config|

config.action_controller.relative_url_root = “/YourApp”
end
======================================================

SYMPTOM: Ruby on rails version ‘2.3.1’ not found
(or some other version)

FIX: Upgrade rails (or install the needed Rails version, more than one can run at once):
sudo gem install rails –version 2.3.1

======================================================

SYMPTOM: Apache does not respond in the browser.

FIX: Make sure that apache is started ok, try this to see if there are any errors in your httpd.conf file:
sudo apachectl configtest

======================================================