【问题标题】:Undefined method `has_attached_file' with paperclip 2.3.8 gem for Rails 2 using Ruby 1.8.7使用 Ruby 1.8.7 的 Rails 2 带有回形针 2.3.8 gem 的未定义方法“has_attached_file”
【发布时间】:2011-08-25 12:51:59
【问题描述】:

我正在尝试使用我的 rails 应用程序中的回形针插件来上传帖子的图片。我在 Ubuntu 10.04 操作系统上使用 Rails 2.0.2 和 ruby​​ 1.8.7 用于项目特定目的。

我指的是以下教程:-

  1. http://railscasts.com/episodes/134-paperclip?view=comments

  2. http://jimneath.org/2008/04/17/paperclip-attaching-files-in-rails.html

我通过:- https://github.com/thoughtbot/paperclip 在回形针插件上做了一个 git clone,但是像 ruby script/generate paperclip group_post photo 这样的命令并没有为它生成迁移。然后,我通过 ruby​​ script/generate 创建了相同的迁移,并上传了我的表 group_posts 的相应列。

然后我尝试安装 gem,由于我使用的是 activerecord 和 activesupport 2.0.2,所以我使用了 ruby​​gems.org 的回形针 2.3.8 gem。未定义的方法错误仍然存​​在,我真的不知道为什么。

现在在这里.. 命令ruby script/generate paperclip group_post photo 对我来说非常好。

我得到的当前错误看起来像这样:-

undefined method `has_attached_file' for #<Class:0xb67119f0>

我观察到这种行为的一个有趣的事情是,当我使用 IRB 时,require 'paperclip' 返回了true,但我想知道为什么他们无法检测到我的 rails 应用程序中的插件附带的方法。

Application Trace 是:-

/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activerecord-2.0.2/lib/active_record/base.rb:1532:in `method_missing_without_paginate'
vendor/plugins/will_paginate/lib/will_paginate/finder.rb:170:in `method_missing'
app/models/group_post.rb:9
app/controllers/groups_controller.rb:27:in `show'

为了以防万一,Full Trace是:-

/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activerecord-2.0.2/lib/active_record/base.rb:1532:in `method_missing_without_paginate'
vendor/plugins/will_paginate/lib/will_paginate/finder.rb:170:in `method_missing'
app/models/group_post.rb:9
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:203:in `load_without_new_constant_marking'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:203:in `load_file'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in `new_constants_in'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:202:in `load_file'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:94:in `require_or_load'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:248:in `load_missing_constant'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:453:in `const_missing_not_from_s3_library'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/aws-s3-0.6.2/lib/aws/s3/extensions.rb:206:in `const_missing'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:465:in `const_missing'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:471:in `send'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:471:in `const_missing'
app/controllers/groups_controller.rb:27:in `show'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-2.0.2/lib/action_controller/base.rb:1158:in `send'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-2.0.2/lib/action_controller/base.rb:1158:in `perform_action_without_filters'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-2.0.2/lib/action_controller/filters.rb:697:in `call_filters'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-2.0.2/lib/action_controller/filters.rb:689:in `perform_action_without_benchmark'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-2.0.2/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
/home/mohnish/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/benchmark.rb:293:in `measure'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-2.0.2/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-2.0.2/lib/action_controller/rescue.rb:199:in `perform_action_without_caching'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-2.0.2/lib/action_controller/caching.rb:678:in `perform_action'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activerecord-2.0.2/lib/active_record/connection_adapters/abstract/query_cache.rb:33:in `cache'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activerecord-2.0.2/lib/active_record/query_cache.rb:8:in `cache'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-2.0.2/lib/action_controller/caching.rb:677:in `perform_action'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-2.0.2/lib/action_controller/base.rb:524:in `send'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-2.0.2/lib/action_controller/base.rb:524:in `process_without_filters'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-2.0.2/lib/action_controller/filters.rb:685:in `process_without_session_management_support'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-2.0.2/lib/action_controller/session_management.rb:123:in `process_without_test'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-2.0.2/lib/action_controller/test_process.rb:15:in `process'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-2.0.2/lib/action_controller/base.rb:388:in `process'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:171:in `handle_request'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:115:in `dispatch'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:126:in `dispatch_cgi'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:9:in `dispatch'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/lib/mongrel/rails.rb:76:in `process'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/lib/mongrel/rails.rb:74:in `synchronize'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/lib/mongrel/rails.rb:74:in `process'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/lib/mongrel.rb:159:in `process_client'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/lib/mongrel.rb:158:in `each'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/lib/mongrel.rb:158:in `process_client'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `run'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `initialize'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `new'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `run'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `initialize'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `new'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `run'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/lib/mongrel/configurator.rb:282:in `run'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/lib/mongrel/configurator.rb:281:in `each'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/lib/mongrel/configurator.rb:281:in `run'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/bin/mongrel_rails:128:in `run'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/lib/mongrel/command.rb:212:in `run'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/bin/mongrel_rails:281
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in `load'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in `load'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in `new_constants_in'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in `load'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/rails-2.0.2/lib/commands/servers/mongrel.rb:64
/home/mohnish/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
/home/mohnish/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in `new_constants_in'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/rails-2.0.2/lib/commands/server.rb:39
/home/mohnish/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
/home/mohnish/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
script/server:3

我的 groups_controller.rb 显示方法是这样的,这里第 27 行是@group_post = GroupPost.new(params[:group_post]) :-

  def show
    @investor_group = InvestorGroup.find(params[:id])
    @members = @investor_group.activated_members
    # code taken from discuss method
    investor_id = session['investor_id']
    @investor = Investor.find(investor_id)

    @members = @investor_group.activated_members

    unless @current_user.is_an_existing_member_of_group(@investor_group)
        flash[:notice] = "Please join this group to participate in discussions"
        redirect_to :action => :show, :id => @investor_group and return
    else
       @group_post = GroupPost.new(params[:group_post]) # line 27, tried GroupPost.create also.. seems to be of no avail..
    end
    #@group_post = GroupPost.new(params[:group_post])
      @group_post.investor_group_id = @investor_group.id
      @group_post.post_by = investor_id
    unless @group_post.message.blank?
      if @group_post.save
        flash[:notice] = 'Post was successfull'
     else
        flash[:notice] = 'Post was not successfull'
      end
       #redirect_to :action => :show, :id => @investor_group and return to change.. appropriately....
    end
    #if @group_post.message.blank?
    #  flash[:notice] = 'Post can\'t be blank.'
    #end
    @group_all_posts  = GroupPost.find(:all, :conditions => [ 'investor_group_id = ?', "#{@investor_group.id}" ], :order => 'created_at DESC')
    # code taken from discuss method
  end

group_post 模型如下所示,第 9 行代码如下 has_attached_file :photo :-

class GroupPost

#include 回形针 需要“回形针” # 回形针 has_attached_file :photo # 第 9 行

结束

我尝试上传图片和帖子的部分视图文件如下所示:-

<%form_for  :group_post, @group_post, :url => {:action => :show},:html => {:multipart => 'true'},:id => 'new_post' do |f| -%>
    <p><label>Start Discussion:</label><br><%=f.text_field :message%></p>
   <%=f.file_field :photo%></p> 
   <p><%=submit_tag "Post"%></p>
  <%end%>

我尝试了以下内容:-

这个选项似乎不适用于我的情况,因为它似乎使用了 更高的 Rails 版本

我尝试了包含回形针 - 但它似乎对我的情况没有帮助...

我在 group_post.rb 和 environment.rb 文件中添加了一个 require “paperclip”。我仍然得到一个未定义的方法错误。不知道为什么。。

在提到这个时,我尝试了 Imumar 的回形针叉子,在 git 克隆它之后,我手动将它粘贴到我的供应商/插件目录中。我收到以下错误(我觉得肯定会有依赖问题,因为他的版本可能仅与更高的 rails 版本兼容:

mohnish@mohnish-desktop:~/UP/dev$ ruby script/server -p 4000
=> Booting Mongrel (use 'script/server webrick' to force WEBrick)
=> Rails application starting on http://0.0.0.0:4000
=> Call with -d to detach
=> Ctrl-C to shutdown server
** Starting Mongrel listening at 0.0.0.0:4000
** Starting Rails with development environment...
Exiting
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:263:in `load_missing_constant': uninitialized constant Paperclip::CallbackCompatability::Rails20 (NameError)
    from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:453:in `const_missing'
    from /home/mohnish/UP/dev/vendor/plugins/paperclip/lib/paperclip.rb:118:in `included'
    from /home/mohnish/UP/dev/vendor/plugins/paperclip/lib/paperclip.rb:364:in `include'
    from /home/mohnish/UP/dev/vendor/plugins/paperclip/lib/paperclip.rb:364:in `send'
    from /home/mohnish/UP/dev/vendor/plugins/paperclip/lib/paperclip.rb:364
    from /home/mohnish/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
    from /home/mohnish/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
    from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'
    from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in `new_constants_in'
    from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'
    from /home/mohnish/UP/dev/vendor/plugins/paperclip/init.rb:1:in `evaluate_init_rb'
    from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/rails-2.0.2/lib/rails/plugin.rb:79:in `evaluate_init_rb'
    from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/core_ext/kernel/reporting.rb:11:in `silence_warnings'
    from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/rails-2.0.2/lib/rails/plugin.rb:75:in `evaluate_init_rb'
    from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/rails-2.0.2/lib/rails/plugin.rb:39:in `load'
    from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/rails-2.0.2/lib/rails/plugin/loader.rb:33:in `load_plugins'
    from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/rails-2.0.2/lib/rails/plugin/loader.rb:32:in `each'
    from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/rails-2.0.2/lib/rails/plugin/loader.rb:32:in `load_plugins'
    from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/rails-2.0.2/lib/initializer.rb:189:in `load_plugins'
    from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/rails-2.0.2/lib/initializer.rb:105:in `process'
    from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/rails-2.0.2/lib/initializer.rb:49:in `send'
    from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/rails-2.0.2/lib/initializer.rb:49:in `run'
    from /home/mohnish/UP/dev/config/environment.rb:16
    from /home/mohnish/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
    from /home/mohnish/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
    from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'
    from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in `new_constants_in'
    from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'
    from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/bin/../lib/mongrel/rails.rb:147:in `rails'
    from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/bin/mongrel_rails:113:in `cloaker_'
    from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/lib/mongrel/configurator.rb:149:in `call'
    from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/lib/mongrel/configurator.rb:149:in `listener'
    from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/bin/mongrel_rails:99:in `cloaker_'
    from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/lib/mongrel/configurator.rb:50:in `call'
    from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/lib/mongrel/configurator.rb:50:in `initialize'
    from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/bin/mongrel_rails:84:in `new'
    from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/bin/mongrel_rails:84:in `run'
    from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/lib/mongrel/command.rb:212:in `run'
    from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/bin/mongrel_rails:281
    from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in `load'
    from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in `load'
    from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in `new_constants_in'
    from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in `load'
    from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/rails-2.0.2/lib/commands/servers/mongrel.rb:64
    from /home/mohnish/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
    from /home/mohnish/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
    from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'
    from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in `new_constants_in'
    from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'
    from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/rails-2.0.2/lib/commands/server.rb:39
    from /home/mohnish/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
    from /home/mohnish/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
    from script/server:3
mohnish@mohnish-desktop:~/UP/dev$ 

我真的想知道我哪里错了..

任何建议/见解将不胜感激。这对我来说很紧迫,因为我有一个部署到期,我真的很高兴能得到及时的答案/回复..

非常感谢..

【问题讨论】:

    标签: ruby-on-rails ruby file-upload paperclip ruby-on-rails-plugins


    【解决方案1】:

    有点相关,决定把这个放在这里给未来的谷歌人。

    在 Ruby 1.8.7 上使用 Rails 2.3.14 和 bundler。正如thoughtbot 所建议的,我正在使用回形针 2.7,即我的 gemfile 包含:

    gem "paperclip", "~> 2.7.0"
    

    我还收到“未定义方法”错误。为我解决的问题是将paperclip.rbfile 放入config/initializers,其中包含以下内容:

    require "paperclip/railtie"
    Paperclip::Railtie.insert
    

    希望这会让人有点头疼。

    【讨论】:

    • 为我解决了这个问题,我使用的是 rails 3.2.11 和回形针 3.4.0
    • 也解决了我的问题,在带有 Paperclip 2.7.5 的古老 Rails 2.3.18 项目中
    【解决方案2】:

    好的,首先,只是为了覆盖“显而易见的”基础:执行“ls vendor/plugins”只是为了确保某个版本的回形针实际上在您的插件目录中,因此您的应用程序可以访问。

    其次 - model 中的“需要回形针”对我来说似乎是错误的。我猜 require 应该进入你的环境。试着把它放在 config/environments.rb 的末尾。

    第三(可能与您的具体问题无关)- 2.0.2 是一个非常旧的 rails 版本。如果可以的话,我会升级到 2.3.5,或者至少升级到 2.2.x。据我们所知,您可能会遇到问题,因为您有一个新版本的回形针和一个旧版本的导轨……这有时确实会产生影响。

    您发布的许多其他链接都涉及到 Rails3 的安装 - 因此,他们的问题的解决方案将与您的不同。

    【讨论】:

    • - 你非常正确..“你有一个新版本的回形针和一个旧版本的导轨......”是我的确切问题......我必须使用它来修复它来自 github 的 8may08 提交的回形针插件.. 修复了这个问题.. 实际上大约一周前... 发布了一个类似的问题,我得到了与您类似的答案/解决方案..谢谢...:)
    • 没有问题。很高兴你最终把它整理好了:)
    猜你喜欢
    • 2018-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多