Rails迁移抱怨使用回形针的未定义方法“附件" [英] Rails migration complains about undefined method `attachment' using paperclip

查看:57
本文介绍了Rails迁移抱怨使用回形针的未定义方法“附件"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Lemmie只是以说我是Rails的新手来作为开头.

Lemmie just preface this by saying I'm fairly new to Rails.

我们的应用程序使用回形针(3.2.4)管理附件,并且像往常一样,我生成了一个类似于以下内容的迁移文件:

Our app uses paperclip (3.2.4) to manage attachments and as usual, I generated a migration that looks something like:

class AddAttachmentPhotoToPhpfoxUsers < ActiveRecord::Migration
  def self.up
    change_table :phpfox_user do |t|
      t.attachment :photo
    end
  end

  def self.down
    drop_attached_file :phpfox_user, :photo
  end
end

(之所以称为phpfox_user,是因为我们必须在旧版数据库的基础上进行构建)

(It's called phpfox_user because we have to build on top of a legacy db)

那太好了,效果很好.但是,我们还必须管理2个数据库以及向它们的迁移,因此我根据这篇文章的建议重新安排了迁移:

That's all great, works fine. However, we have to manage 2 databases and migrations to them as well, so I rearranged the migrations according to the suggestions on this post:

http://excid3.com/blog/rails-activerecord-多个数据库和迁移

我不知道这应该有多好,但是,这似乎是一个相当整洁的解决方案,它可以很好地组织迁移.

I don't know how good this is supposed to be, but it seems to a fairly neat solution and it organises the migrations quite well.

但是,由于找不到附件类型,因此回形针迁移现在不起作用.我假设它不再在范围内或没有绑定到表对象.有谁知道将其引入该怎么做,我试图在模块中添加require'paperclip',但这无济于事.

However now the paperclip migration doesn't work as it can't find the attachment type. I'm assuming it's no longer in scope or hasn't bound to the table object. Does anyone have any idea what I should do to bring it in, I've tried adding require 'paperclip' to the module but that doesn't help.

我也尝试过使用add_attachment帮助器,但也找不到.

I've also tried using the add_attachment helper and that's also not found.

我们正在使用Rails 3.2.13和Ruby 2.0.0.

We're using Rails 3.2.13 and Ruby 2.0.0.

错字

推荐答案

好,知道了.add_attachment帮助器在schema.rb文件中定义.不知道是否正确,但我是否包括:

Ok, figured it out. The add_attachment helper is defined in the schema.rb file. Don't know if it's right or not but if I include:

include Paperclip::Schema

进入文件,它可以正常工作.

into the file, it works.

这篇关于Rails迁移抱怨使用回形针的未定义方法“附件"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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