Skip to main content
Ask A Question
You’re not receiving notifications from this thread.

Refile uploading via rails console

General • Asked by Brian Schwartz

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


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

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?

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

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.

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

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.

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?


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?

Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 30,005+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.