2011-06-05 21 views
3

我是非常新的Rails,我正在運行Rails 3 我最近通過Homebrew安裝了ImageMagick,然後運行'sudo plugin install git://github.com/thoughtbot/paperclip.git 'Rails 3回形針安裝,現在得到LoadError

我在我的根Gemfile中添加了「gem'rmagick'」。

這樣做後立即發現沒有rails命令工作了(下面的錯誤)。我嘗試添加「config.gem」rmagick「,:lib =>」RMagick「」作爲其他線程建議的environment.rb,但是這會返回一個不同的錯誤(未定義的局部變量或方法`配置'爲main:Object NameError))

有什麼想法?

/opt/local/lib/ruby/gems/1.8/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:239:in `require': no such file to load -- cocaine (LoadError) 
from /opt/local/lib/ruby/gems/1.8/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:239:in `require' 
from /opt/local/lib/ruby/gems/1.8/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:225:in `load_dependency' 
from /opt/local/lib/ruby/gems/1.8/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:596:in `new_constants_in' 
from /opt/local/lib/ruby/gems/1.8/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:225:in `load_dependency' 
from /opt/local/lib/ruby/gems/1.8/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:239:in `require' 
from /Users/tonybeninate/Documents/Apps/PhotoBlog/vendor/plugins/paperclip/lib/paperclip.rb:43 
from /opt/local/lib/ruby/gems/1.8/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:239:in `require' 
from /opt/local/lib/ruby/gems/1.8/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:239:in `require' 
from /opt/local/lib/ruby/gems/1.8/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:225:in `load_dependency' 
from /opt/local/lib/ruby/gems/1.8/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:596:in `new_constants_in' 
from /opt/local/lib/ruby/gems/1.8/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:225:in `load_dependency' 
from /opt/local/lib/ruby/gems/1.8/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:239:in `require' 
from /Users/tonybeninate/Documents/Apps/PhotoBlog/vendor/plugins/paperclip/lib/paperclip/railtie.rb:1 
from /opt/local/lib/ruby/gems/1.8/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:239:in `require' 
from /opt/local/lib/ruby/gems/1.8/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:239:in `require' 
from /opt/local/lib/ruby/gems/1.8/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:225:in `load_dependency' 
from /opt/local/lib/ruby/gems/1.8/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:596:in `new_constants_in' 
from /opt/local/lib/ruby/gems/1.8/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:225:in `load_dependency' 
from /opt/local/lib/ruby/gems/1.8/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:239:in `require' 
from /Users/tonybeninate/Documents/Apps/PhotoBlog/vendor/plugins/paperclip/rails/init.rb:1 
from /opt/local/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/plugin.rb:81 
from /opt/local/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/initializable.rb:25:in `instance_exec' 
from /opt/local/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/initializable.rb:25:in `run' 
from /opt/local/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/initializable.rb:50:in `run_initializers' 
from /opt/local/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/initializable.rb:49:in `each' 
from /opt/local/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/initializable.rb:49:in `run_initializers' 
from /opt/local/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/application.rb:134:in `initialize!' 
from /opt/local/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/application.rb:77:in `send' 
from /opt/local/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/application.rb:77:in `method_missing' 
from /Users/tonybeninate/Documents/Apps/PhotoBlog/config/environment.rb:5 
from /Users/tonybeninate/Documents/Apps/PhotoBlog/config.ru:3:in `require' 
from /Users/tonybeninate/Documents/Apps/PhotoBlog/config.ru:3 
from /opt/local/lib/ruby/gems/1.8/gems/rack-1.2.3/lib/rack/builder.rb:46:in `instance_eval' 
from /opt/local/lib/ruby/gems/1.8/gems/rack-1.2.3/lib/rack/builder.rb:46:in `initialize' 
from /Users/tonybeninate/Documents/Apps/PhotoBlog/config.ru:1:in `new' 
from /Users/tonybeninate/Documents/Apps/PhotoBlog/config.ru:1 
+1

如果有幫助,您可以在這裏查看我的應用程序:https://github.com/tbhockey/PhotoBlog – 2011-06-05 22:08:45

回答

3

我克隆你的回購和運行的應用程序,但沒有得到任何這些錯誤。你有沒有嘗試安裝回形針作爲寶石而不是插件?

這是我在我的應用程序(使用Amazon S3存儲)的一個工作設置:

# Gemfile 
gem 'paperclip' 
gem 'aws-s3' 

#MyModel migration 
class MyModel < ActiveRecord::Migration 
    def self.up 
    create_table :my_model do |t| 
     t.string :name 
     t.text :description 
     t.string :image_file_name 
     t.string :image_content_type 
     t.integer :image_file_size 
     t.datetime :image_updated_at 

     t.timestamps 
    end 
    end 
end 


#MyModel.rb 
has_attached_file :image, 
:storage => :s3, 
:s3_credentials => "#{RAILS_ROOT}/config/amazons3.yml", 
:path => "pictures/:id.:extension" 


#config/amazons3.yml 
development: 
    access_key_id: MY_ACCESS_KEY_ID 
    secret_access_key: MY_SECRET_KEY 
    bucket: myBucket 

test: 
    access_key_id: MY_ACCESS_KEY_ID 
    secret_access_key: MY_SECRET_KEY 
    bucket: myBucket 

production: 
    access_key_id: MY_ACCESS_KEY_ID 
    secret_access_key: MY_SECRET_KEY 
    bucket: myBucket 


#app/views/my_model/_form.html.haml 
= form_for @my_model_instance, :html => {:multipart => true} do |f| 
    %fieldset 
    = f.label :name 
    = f.text_field :name 
    %fieldset 
    = f.label 'Attach Image' 
    = f.file_field :image 
    %fieldset 
    = f.label :description 
    = f.text_area :description 
    %fieldset 
    = f.submit 'Save', :class => 'button' 
+0

你真棒。我可以發誓我添加了'gem'paperclip''到我的gemfile然後運行bundle install;但它不在那裏。我再次做到了,一切都很好!謝謝。 – 2011-06-05 22:44:41

0

如果您在開發模式下運行,你會得到一個錯誤,在終端rails s寫這篇運行發展模式

:s3_credentials => "#{RAILS_ROOT}/config/amazons3.yml", 

變化,工作正確使用Rails 3

:s3_credentials => "#{Rails.root}/config/amazons3.yml",