Carrierwave and the Rails Console/Runner

1,154 views
Skip to first unread message

JS

unread,
May 22, 2012, 5:57:27 AM5/22/12
to carrierwave
Hi guys,

I'm trying to work out how to use Carrierwave from the Rails Console
and a Rails Runner script. I've been searching but I can't really find
any good information on what's the best way to do it.

What I'm trying to achieve is a batch upload script that uses the same
settings our Rails application is using. I want to run this from the
rails runner.

Essentially I'm looking for the console commands that will create an
ActiveRecord record and upload (via Fog) a local file using
Carrierwave.

I've seen examples like this mentioned in other threads;
----
file = File.open("<path_to_local_file")
uploader = ImageUploader.new
image = Image.new
image.image = file
image.save
----
But without explanation it's hard to figure out what image.image is,
and why an instance of ImageUploader is created but not used. :)

Thanks for your insight!

/JS

Jacob Tjørnholm

unread,
Jun 5, 2012, 9:14:59 AM6/5/12
to carri...@googlegroups.com
Hi, 

On a project I have a Page model with an "image" uploader mounted. 
Here's an example of how I can upload from the console: https://gist.github.com/2874877

As you can see, the uploader has a thumbnail version as well.

/Jacob




/JS

--
You received this message because you are subscribed to the Google Groups "carrierwave" group.
To post to this group, send email to carri...@googlegroups.com.
To unsubscribe from this group, send email to carrierwave...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/carrierwave?hl=en.


JS

unread,
Jun 6, 2012, 6:00:47 AM6/6/12
to carrierwave


On Jun 5, 2:14 pm, Jacob Tjørnholm <cho...@gmail.com> wrote:
> On a project I have a Page model with an "image" uploader mounted.
> Here's an example of how I can upload from the console:https://gist.github.com/2874877
>
> As you can see, the uploader has a thumbnail version as well.

Hi Jacob,

Thanks for that! I did actually figure it out and the bottom line is
that the "carrierwav'd" models behave just like ordinary models, but
when creating a new one, the property that has got an Uploader mounted
will take a File instance as argument, just as your example shows.
Also, once saved, you'll get the carrierwave specifics out of it. It's
all quite nifty, albeit a bit hidden.

Either way, thank you for your input and apologies for not informing
that I did manage to find the solution.

Cheers,

/JS
Reply all
Reply to author
Forward
0 new messages