Forum: Ruby on Rails Newbie File_Column and Console Question.

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Shai S. (Guest)
on 2006-04-04 22:37
I recently got File_Column installed and working and it is great, but
now I find myself needing to resize all the images I already uploaded.

Through the web I found that the answer lies in going to the
script/console and adding:

Attachment.find(:all).each do |a|
    a.asset = File.open(a.asset)
    a.save
end

But what exactly do I do next, I tried running it with no success. How
can I make it work?

Thanks!
sshefer (Guest)
on 2006-04-07 06:00
(Received via mailing list)
> end
>
> But what exactly do I do next, I tried running it with no success. How
> can I make it work?
>
> Thanks!
>

Here's some more information it it will help.

The model I have is for my Products, with image as the
attribute for the file_column file.

I went into the console, and selected all of my products
that do not have a file name in the image field, so that
I would only get the products with current images.

So with that I made a loop to go through each product:
>> for product in @products
>> product.image = File.open(product.image)
>> product.save
>> end

Now the loop works, I get no errors, but every file is
loaded into the tmp folder!

After sorting through the returned array I noticed:
#<Product:0x2503acc @errors=#<ActiveRecord::Errors:0x2476500
@errors={"image"=>["invalid image"]},


Can anyone guide me on the next step? I've searched everywhere
but cant seem to find a solution!

Thanks
Shai S. (Guest)
on 2006-04-11 05:38
(Received via mailing list)
sshefer <sshefer@...> writes:


> > I recently got File_Column installed and working and it is great, but
> > now I find myself needing to resize all the images I already uploaded.
> >
>
> I went into the console, and selected all of my products
> that do not have a file name in the image field, so that
> I would only get the products with current images. But it doesn't seem
> to create the new version, just load it into tmp dir.

Can anyone else help?

I've searched every conceivable place for it with no luck, is this even
possible? I'd like to know and add to the File Column HowTwo, as this
seems to
be a common question with no replies!

Anyone? Any help/guidance would be appreciated.
Robert D. (Guest)
on 2006-04-11 05:50
shai shefer wrote:
> sshefer <sshefer@...> writes:
>
>
>> > I recently got File_Column installed and working and it is great, but
>> > now I find myself needing to resize all the images I already uploaded.
>> >
>>
>> I went into the console, and selected all of my products
>> that do not have a file name in the image field, so that
>> I would only get the products with current images. But it doesn't seem
>> to create the new version, just load it into tmp dir.
>
> Can anyone else help?
>
> I've searched every conceivable place for it with no luck, is this even
> possible? I'd like to know and add to the File Column HowTwo, as this
> seems to
> be a common question with no replies!
>
> Anyone? Any help/guidance would be appreciated.

Shai,

I believe that if you look at the File_Column docs it will tell you that
File_Column works with ImageMagick (on Linux) in order to resize images
on upload. You can even create multiple versions of the same file. I
hope this helps.

Good luck,

Rob D.
Shai S. (Guest)
on 2006-04-11 06:15
(Received via mailing list)
Thanks for the reply...

I looked into doing ImageMagick and running it through the console, but
was
wondering if there wasn't a simpler, more sophisticated manner of
updating
the existing image tree with the new versions.

Is there no way to tie in the new versions set in the Model when opening
an
image and saving it?

I would think this is a common problem, did no one else need to
add/change
image sizes?
--
View this message in context:
http://www.nabble.com/Newbie-File_Column-and-Conso...
Sent from the RubyOnRails Users forum at Nabble.com.
This topic is locked and can not be replied to.