我在運行Apache和Phusion Passenger的登臺/生產機器上部署了我的rails應用程序,但無法正確加載Paperclip gem(或至少無法獲得應用程序使用它)。其他寶石似乎加載正常,當我在RAILS_ROOT/config/environments/staging.rb中設置config.cache_classes
到false
時,應用程序的其餘部分工作正常。如果設置爲true,我得到的瀏覽器(和Apache錯誤日誌)以下的乘客信息,並不能在所有使用該應用程序:不能在Apache/Passenger下工作的回形針
Error message:
undefined method `validates_attachment_presence' for #<Class:0xb618e938>
Exception class:
NoMethodError
我周圍一派相當長的一段時間,但無法找到一個解決方案對於我遇到的這個問題。我希望我不能忽略一些明顯的東西...
更新21/8:在與sudo腳本/服務器-b 17x.7x.16x.3x -e分段工作正常運行軌應用程序相同的盒子工作正常。這可能是一個權限問題,乘客無法找到已安裝的Paperclip Gem?
希望你能給我一些指點,讓我知道如果你需要更多的信息!感謝馬克
在我的環境中的某些信息:
$ rails -v
Rails 2.3.5
RAILS_ROOT /配置/ environment.rb中有這一套:
config.gem "paperclip", :version => "~> 2.3"
寶石環境:
$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.5
- RUBY VERSION: 1.8.7 (2010-01-10 patchlevel 249) [i486-linux]
- INSTALLATION DIRECTORY: /var/lib/gems/1.8
- RUBY EXECUTABLE: /usr/bin/ruby1.8
- EXECUTABLE DIRECTORY: /var/lib/gems/1.8/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-linux
- GEM PATHS:
- /var/lib/gems/1.8
- /home/mark/.gem/ruby/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://gems.rubyforge.org/
寶石上列出服務器:
$ gem list
*** LOCAL GEMS ***
abstract (1.0.0)
actionmailer (3.0.9, 2.3.5)
actionpack (3.0.9, 2.3.5)
activemodel (3.0.9)
activerecord (3.0.9, 2.3.5)
activeresource (3.0.9, 2.3.5)
activesupport (3.0.9, 2.3.5)
arel (2.1.3, 2.0.10)
builder (3.0.0, 2.1.2)
capistrano (2.6.0)
cocaine (0.1.0)
daemon_controller (0.2.6)
erubis (2.6.6)
fastthread (1.0.7)
highline (1.6.2)
i18n (0.4.2)
mail (2.2.19)
mime-types (1.16)
mysql (2.8.1)
net-scp (1.0.4)
net-sftp (2.0.5)
net-ssh (2.1.4)
net-ssh-gateway (1.1.0)
paperclip (2.3.12)
passenger (3.0.7)
polyglot (0.3.1)
rack (1.2.3, 1.1.0, 1.0.1)
rack-mount (0.6.14)
rack-test (0.5.7)
rails (2.3.5)
rake (0.9.2, 0.8.7)
treetop (1.4.9)
tzinfo (0.3.29)
will_paginate (2.3.15)
回形針寶石在這裏安裝:
$ sudo find/-name 'paperclip'
/var/lib/gems/1.8/doc/paperclip-2.3.12/rdoc/files/lib/paperclip
/var/lib/gems/1.8/doc/paperclip-2.3.12/rdoc/files/lib/generators/paperclip
/var/lib/gems/1.8/gems/paperclip-2.3.12/lib/paperclip
/var/lib/gems/1.8/gems/paperclip-2.3.12/lib/generators/paperclip
/var/lib/gems/1.8/gems/paperclip-2.3.12/generators/paperclip
Apache的虛擬主機配置:
$ more /etc/apache2/sites-available/staging.mydomain.com
<VirtualHost *:80>
ServerName staging.mydomain.com
DocumentRoot /u/apps/mydomain.com/current/public
RailsEnv staging
</VirtualHost>
從乘客頁一些額外的堆棧跟蹤(順便說一句:試圖消除will_paginate插件,但結果是完全一樣;它拋出在active_record/base.rb錯誤):
Backtrace:
# File Line Location
0 /var/lib/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb 1959 in `method_missing_without_paginate'
1 /u/apps/mydomain.com/releases/20110705192718/vendor/plugins/will_paginate/lib/will_paginate/finder.rb 170 in `method_missing'
2 /u/apps/mydomain.com/releases/20110705192718/app/models/image.rb 5
3 /usr/lib/ruby/1.8/rubygems/custom_require.rb 31 in `gem_original_require'
4 /usr/lib/ruby/1.8/rubygems/custom_require.rb 31 in `require'
5 /var/lib/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb 158 in `require'
6 /var/lib/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb 265 in `require_or_load'
7 /var/lib/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb 224 in `depend_on'
8 /var/lib/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb 136 in `require_dependency'
9 /var/lib/gems/1.8/gems/rails-2.3.5/lib/initializer.rb 414 in `load_application_classes'
10 /var/lib/gems/1.8/gems/rails-2.3.5/lib/initializer.rb 413 in `each'
代碼圖像類別:
class Image < ActiveRecord::Base
belongs_to :user
validate_attachment_presence :photo
validates_uniqueness_of :photo_file_name, :scope => :user_id
has_attached_file :photo, :url => "/assets/:user/app/:class/:style_:basename.:
extension",
:path => "#{APP_PATH}/:user/app/:class/:style_:basename.:extension",
:styles => {
:thumb=> "50x50#",
:large => "400x" }
end
到config/environment.rb
# Be sure to restart your server when you modify this file
# Specifies gem version of Rails to use when vendor/rails is not present
RAILS_GEM_VERSION = '2.3.5' unless defined? RAILS_GEM_VERSION
# Bootstrap the Rails environment, frameworks, and default configuration
require File.join(File.dirname(__FILE__), 'boot')
Rails::Initializer.run do |config|
config.time_zone = 'UTC'
config.active_record.observers = :user_observer #, :website_observer
config.gem "paperclip", :version => "~> 2.3"
end
SITE_NAME = 'Mydomain.com'
CMS_PREFIX = 'joomla'
配置/ environments.rb/staging.rb
# Settings specified here will take precedence over those in config/environment.rb
# The staging environment is meant for finished, apps and final acceptance testing.
# Code is not reloaded between requests
config.cache_classes = true
# Full error reports are disabled and caching is turned on
config.action_controller.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.action_view.cache_template_loading = true
ActionController::Base.asset_host = "staging.mydomain.com"
DOCUMENT_ROOT = "/var/www"
APP_PATH = "/u/apps"
DB_PREFIX = "a001"
DB_USER = "joomla"
DB_PWD = "*****"
GIT_URL = "[email protected]:****/mydomain.git"
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:enable_starttls_auto => true,
:address => "smtp.gmail.com",
:port => "587",
:domain => "gmail.com",
:authentication => :plain,
:user_name => "****@gmail.com",
:password => "****"
}
服務器上顯示'gem list'是什麼? –
將其添加到原始帖子中。 – Mark
從堆棧跟蹤看來,錯誤來自app/models/image.rb的第5行 - 您是否也可以在此處發佈模型代碼? –