NoMethodError: undefined method `has_attached_file' 无法定义方法“has_attached_file”的错误

7
在检查了插件的rails3分支后,Paperclip产生了这个错误。我的Gemfile文件有以下行:
gem 'paperclip', :git => 'http://github.com/thoughtbot/paperclip.git', :branch => 'rails3'

错误信息如下:

NoMethodError: undefined method `has_attached_file' for #<Class:0x2a50530>
5个回答

15

更新06-21-10: thoughtbot的版本已经修复。

我不得不在我的application.rb文件的class Application < Rails::Application结尾处添加Paperclip :: Railtie.insert,才能使它正常工作。由于官方仓库已经可以正常工作,因此我已删除了我的fork。希望这能帮助到某些人。

您还需要将以下内容添加到您的Gemfile

gem "paperclip", :git => "http://github.com/thoughtbot/paperclip.git"

3

我有一个纸片叉子,你可以试试看它是否适用于你的环境,只需更改您的Gemfile:

gem 'paperclip', :git => 'git://github.com/lmumar/paperclip.git', :branch => 'rails3'

在更新 Gemfile 后,不要忘记运行 bundle install。

希望它能解决你的问题。

lmumar


在评估paperclip.gemspec时出现了LoadError。 它是否尝试要求相对路径?这在Ruby 1.9中不起作用。 - mirza
谢谢 - 对我很有用 :-) 这会让我继续下去,直到主程序完全修复为Rails3。 - firecall
这个 fork 对我也起作用了。希望 thoughtbot 很快就会从 lmumar 进行合并 :) - Sam Soffes

1

minter的分叉对我起作用了:

gem 'paperclip', :git => 'http://github.com/minter/paperclip.git', :branch => 'rails3'

1

对我来说那行不通。 我已经做了以下的事情,现在它完美地运作:

  • 在application.rb中添加"Paperclip::Railtie.insert"
  • 在development.rb中添加"config.gem 'paperclip'"

-1

它与Jason King的paperclip版本兼容:

gem 'paperclip', :git => 'http://github.com/JasonKing/paperclip.git', :branch => 'rails3'

这似乎不再存在。 - Sam Soffes

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接