Rails 3 回形针安装,现在得到 LoadError [英] Rails 3 paperclip install, now get LoadError

查看:36
本文介绍了Rails 3 回形针安装,现在得到 LoadError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 Rails 很陌生,我正在运行 Rails 3我最近通过 Homebrew 安装了 ImageMagick,然后运行 ​​'sudo plugin install git://github.com/thoughtbot/paperclip.git'

I am very new to Rails, I am running Rails 3 I recently installed ImageMagick via Homebrew and then ran 'sudo plugin install git://github.com/thoughtbot/paperclip.git'

我在我的根 Gemfile 中添加了gem 'rmagick'".

I added "gem 'rmagick'" to my root Gemfile.

这样做后,我立即发现任何 rails 命令都不再起作用(下面的错误).我尝试将 "config.gem "rmagick", :lib => "RMagick"" 添加到我的 environment.rb 就像其他一些线程建议的那样,但这会返回一个不同的错误(未定义的局部变量或 main:Object 的方法`config'(名称错误))

Immediately after doing so I found that no rails commands worked anymore (error below). I tried adding "config.gem "rmagick", :lib => "RMagick"" to my environment.rb as some other threads suggested, but this returns a different error (undefined local variable or method `config' for 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

推荐答案

我克隆了您的存储库并运行了该应用程序,但没有遇到任何这些错误.您是否尝试将回形针安装为 gem 而不是插件?

I cloned your repo and ran the app but didn't get any of those errors. Have you tried installing paperclip as a gem instead of a plugin?

这是我在我的一个应用程序中使用的设置(使用 Amazon S3 进行存储):

This is the setup I have working in one of my apps (using Amazon S3 for storage):

# 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'

这篇关于Rails 3 回形针安装,现在得到 LoadError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆