Ask A Question

Notifications

You’re not receiving notifications from this thread.

Refile uploading via rails console

Brian Schwartz asked in General

So I'm using Refile and I'm trying to migrate some existing data that I need when I seed the database (migrating to Refile from existing solution and need to keep existing data).

When I try testing my data in the console, it saves the image meta data, but not the image.

Here's what I'm doing example:

class Page < ActiveRecord::Base
  attachment :image 
  attachment :full_size_image
      ....

end

page = Page.new(name: "Issue 3 Cover", title: "Issue 3 Cover", issue_id: 3, position: 1, center_image: true, in_index: false, published: 1)
page.image = File.open('/Users/creativereason/Downloads/issue-10_001-issue-10-cover-small.jpg')
page.save

The result of that is a the metadata being saved, but the image being nil in the database. As far as I can tell, the data is in the bucket on S3 I'm using too.

Any ideas?

Reply

Are there errors on the page model after save? If you load it fresh out of the database, does the image attribute exist?

Reply

No errors. Image is nil both in database and when I load it fresh out of database. I have FriendlyId on that model as well as RankedModel, so I'm wondering if they have anything to do with it. I'm going to disable temporarily to see if they do.

Reply

Solved it. Apparently my migration had my image saved as the wrong name (image instead of image_id).

Reply

Ah ha! I was going to suggest that because I couldn't imagine why everything else was working just fine. Hate when things fail silently like that.

Reply

Me too!


Another question (I could create another thread if you don't have a quick answer).

I have a whole bunch of images already stored on s3 that I don't want to transfer every time I run seeds. Any way you can think of save them out in a seeds file that doesn't force a re-upload? Is that refile ID anyway tied to an item from S3?

Thanks!

Reply

I'm not entirely sure on that one. I imagine you could write the same value in and then save without callbacks in your seeds in order to populate but not trigger Refile to do a reupload?

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 86,946+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.