Reputation: 1825
Lemmie just preface this by saying I'm fairly new to Rails.
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
(It's called phpfox_user because we have to build on top of a legacy db)
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-multiple-databases-and-migrations
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.
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.
I've also tried using the add_attachment helper and that's also not found.
We're using Rails 3.2.13 and Ruby 2.0.0.
edit: typo
Upvotes: 2
Views: 4563
Reputation: 9
I am using ruby 2.1.5 and rails 4.2.1
I pulled code from git after my partner added paperclip gem
I downloaded paperclip gem, added to my gemfile (our gemfiles are different), but did not specify version of paperclip.
So I was surprised that I had to use 'has_attached_file' (which is for older versions of paperclip)
I had to:
1)include paperclip::Schema in schema.rb 2)replace attachment with has_attached_file 3)rake db:migrate
Upvotes: 1
Reputation: 1825
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.
Upvotes: 5
Reputation: 15492
Make sure paperclip (possibly latest version) is present in your Gemfile, run bundle install
and then run
bundle exec rake db:migrate
It should just work.
Upvotes: 1