File_column 0.3.1 with SVN repository

Line two or three of file_column.rb loads magick_file_column.rb too
early. Delete it. magick_file_column.rb will be loaded later by
init.rb. Fixed in SVN. Thanks for the report.

On 11/17/05, Vamsee K. [email protected] wrote:

Please correct me if I’m wrong, but a little playing with file_column
tells me that the file name is being stored in the file_column and it
will be retrieved for display from the saved place from the /public
folder. Is there a way I can save the image itself in the file column
(that was my original assumption). Which approach is better? Saving
images/files in the database or a regular file system?

you’re right, the file itself is stored in the filesystem. I believe
this is better (and in this sense, file_column is oppinionated
software), because rails’ handling of binary data in the database
isn’t very efficient and there is no real reason to put it in the
database anyways. In short, file systems should be pretty good at
storing files… :slight_smile:

Sebastian

On Nov 17, 2005, at 2:40 AM, Vamsee K. wrote:

Sebastian K. wrote:

Hi there,

I’m happy to announce a new minor release of file_column. It contains
two small fixes.

Hey there folks-

I have a small issue with file_column. In a model that displays home

floor plans I have 2 file_columns. Everything works great for
inputting a new record with 2 photos and saving it and even
displaying it with a show action. Where I run into trouble is when
you want to edit a record that already exists. But I just want to
change some text and have the images left alone. What happens is the
edit form assumes that you want to add new photos and so it displays
the file upload buttons. I already tried to make the edit view just
show the image path text that is stored in the db but when you submit
the edit it all blows up because it is expecting files for those
attributes

Am I missing something? How do you make it work so the edit page

will let you either upload new photos or leave the old ones alone
without the need to re-upload them every time I just want to edit
some other text fields?

Help?

Thanks-
-Ezra Z.
Yakima Herald-Republic
WebMaster

509-577-7732
[email protected]

On Nov 19, 2005, at 3:13 AM, Sebastian K. wrote:

there and tell your users to simply not submit anything. This should
keep the old image. Alternatively you can completely leave out an
input element for the image fields. This way, nothing should change
either.

Hope this helps
Sebastian

Sebastian-

OK thanks. I have it working now by just having them leave the file

upload fields alone. That works fine.

Cheers-

-Ezra Z.
WebMaster
Yakima Herald-Republic Newspaper
[email protected]
509-577-7732

Hi Ezra,

On 11/17/05, Ezra Z. [email protected] wrote:

    Am I missing something? How do you make it work so the edit page

will let you either upload new photos or leave the old ones alone
without the need to re-upload them every time I just want to edit
some other text fields?

you basically have two options: Either leave the file upload button
there and tell your users to simply not submit anything. This should
keep the old image. Alternatively you can completely leave out an
input element for the image fields. This way, nothing should change
either.

Hope this helps
Sebastian

I’m just starting to learn Ruby so please forgive the bombarding of
questions.

What is the syntax then if I wanted to crop an image say 80x80 with
center
weigthing (belive it’s -gravity)? I want to always create an 80x80
square
thumb and then a series of propotional images.

Can all of this be done by setting the model? Right now my model looks
like
this:

file_column :gallery_thumbnail, :magick => {
:versions => { “thumb” => “80x80” }
}

What should it look like to accomplish what I describe above.

Many thanks for any assistance anyone can provide.

Kyle H.
[email protected]

Hi Kyle,

On 11/24/05, Kyle H. [email protected] wrote:

What is the syntax then if I wanted to crop an image say 80x80 with center
weigthing (belive it’s -gravity)? I want to always create an 80x80 square
thumb and then a series of propotional images.

unfortunately, the current stable release does not support this, yet.
However, the project’s “trunk” allows you to do the following:

<%= url_for_image_column @entry, “image”, :size =>“80x80”, :crop =>
“1:1” %>

The same thing can be specified in the model as well. Note, however,
that the code is still a bit rough and may have some bugs. Hopefully,
a new release will follow shortly.

Sebastian

hi Kyle,
a per earlier on this thread (see Kyle M.'s posts about his
branch), FileColumn is moving towards doing the processing in the
view… not positive about the syntax in your case, but I’d try
something like

url_for_file_column “your_model”, “gallery”, :magick => { :gravity =>
“Center”, :crop => “80x80”}

or

url_for_file_column “your_model”, “gallery”, :magick => { “-gravity
Center -crop 80x80”}

if neither work, I’d look more into how the imagemagick commands
interact

hope this helps,
Oliver

2005/11/23, Kyle H. [email protected]:

Hi all,

First of all, thanks for the great work on file_column, I’m having some
weird problems though, maybe soemone can help me out.

Uploading works but the uploaded files have the wrong permission (600)
so I can’t show them without manually changing the permission.

Another problem is with file_column in combination with magick.

I have a model like this:

class Note < ActiveRecord::Base
file_column :image, :magick => { :versions => { “thumb” => “100x100”,
“medium” => “640x480>” }}
end

Now, If I understand correctly, this would result in directories like:
‘public/note/image/26/thumb/’ and ‘public/note/image/26/medium/’
containing the images. However, instead of the ‘thumb’ and ‘medium’
directory I get directories with weird names, like ‘2489u2’ and
‘fcfwrb’

Any idea what’s going on here?

Hi Jeroen,

On 11/30/05, Jeroen janssen [email protected] wrote:

Uploading works but the uploaded files have the wrong permission (600)
so I can’t show them without manually changing the permission.

the permissions are controlled by the process’ umask. I think, if you
set the umask to something more liberal in your environment.rb, you
should be fine.

‘public/note/image/26/thumb/’ and ‘public/note/image/26/medium/’
containing the images. However, instead of the ‘thumb’ and ‘medium’
directory I get directories with weird names, like ‘2489u2’ and
‘fcfwrb’

Any idea what’s going on here?

It looks like you are using the latest version from trunk? I’m
currently playing around with this stuff, so things might change. If
you want something more stable, look at the releases in the “tags”
directory.

The weird names are based on hashing the options used for the hash.
The idea is that you can specify the options in the view, like this,
too:

<%= url_for_image_column “entry”, “image”, “50x50” %>

In this case, file_column has no clue what name to use, that’s why the
hashes are coming into play.

Having said this, I’m considering changing the default name for
versions declared in the model the way you described. You can always
set a custom name, via the :name option:

:versions => { :thumb => {:size => “50x50”, :name => “foo” } }

Sebastian

I’ve run into a problem using both file_column (latest SVN release) and
RMagick within the same app. Ever since I installed the plugin my “old
style” non-file_column uploads/image processing code stopped working.
I’d
get the error:

“Uninitialized Constant ‘Image’”

which didn’t make much sense. The code looked something like this:

Image Model

require ‘RMagick’
def process

img = Magick::Image.read( @file.path ) <-- it’d die here

end

Eventually, when I did a logger.debug Magick, it was more obvious. This
is
the output:

FileColumn::Magick

Is there a namespace collision here? What’s going on. I’m in the process
of
converting my site to use file_column, but until thats complete I have
to
use both methods. Is there a way to avoid having file_column collide
with
RMagick in this way?

Thanks
Adam

On 12/12/05, Kris [email protected] wrote:

I am using file_column 0.3.1 and would say that the biggest problem is
documentation/examples.

I have a fair bit of documentation in the rdocs, but you have to
generate the docs with “rake plugindocs”. Of course, more docs are
always better, so patches are very welcome! A complete minimal example
(including model, controller, view, schema…) would be nice, too. So
if anybody writes own be sure to send it to me and I’ll include it.

file_column :image,
>             :magick => { :geometry => "100x100>" },
>             :versions => { "thumb" => "50x50>" }

Any ideas?

the syntax for the current svn trunk is “:versions => { :thumb =>
“50x50>” }”, perhaps this is the reason?

Sebastian

I am using file_column 0.3.1 and would say that the biggest problem is
documentation/examples.

RMagick was easy to setup on Windows once the correct download/readme
was found. There is a RMagick installer for Windows which includes
dependancies. You just need to remember to run the postinstall.rb script
afterwards as per readme.

I am having a problem though. Basically I have it all setup, I can
upload and display file which are re-sized as per geometry. But the
versions are not created… no thumbsnails.

My code is:

file_column :image,
            :magick => { :geometry => "100x100>" },
            :versions => { "thumb" => "50x50>" }

Any ideas?

In the file_column trunk, there’s file_compat.rb, which is included
when file_column sees a non-uploaded file, so that the additional
methods of a CGI-uploaded file are present. Take a look at that code
and patch it into your current installation, or use the current trunk
(stability is uncertain, though there’s good test coverage.)

Also, if you are on Ruby 1.8.3, all you have to do to get a remote file
is:

require ‘open-uri’
begin
@picture.filename = open @params[‘picture_url’];
catch
#Open will throw all kinds of exceptions: connection errors, 404’s,
malformed URLs, etc
end

A new question:

I want to offer my users the ability to add images in two ways:

  1. Upload the image
  2. Provide a URL to an existing image. The back-end code will download
    the picture (using Net::HTTP) and save it to disk where file_column
    expectgs it.

…the current catch is that I’d like to be able to use the file_column
helpers for both methods, but I run into a problem. For method #1 I can
do:

@product = Product.new( @params[:product] )
@product.pictures << Picture.new( @params[:picture] )

for method #2, if I can’t seem to get around file_column, ie:

@product = Product.new( @params[:product] )
@picture = Picture.new

Download picture, save to disk code goes here

@picture.filename = @params[‘picture_url’]; <-- # This will die
@product.picutres << @picture

I can’t just “force” a filename. I hope this makes sense.

Any suggestions on how to make this work?

Thanks

Kyle,

Thanks for the suggestions. I have been working off the trunk so this
shouldn’t be too diffucult to implement. A couple issues though:

When I do:

@picture.filename = open @params[‘picture_url’];

I get ‘undefined method `original_filename’ for
#<File:/tmp/open-uri298.0>’

…but when I do:

@picture.filename = File.new(’/tmp/foo/bar.png’);

it runs correctly. Any idea on getting that open-uri download code
working correctly (or am I missing something)?

Thanks again. You’ve been helpful.

Adam

On 12/20/05, adam roth [email protected] wrote:

I get ‘undefined method `original_filename’ for

http://lists.rubyonrails.org/mailman/listinfo/rails

irb:> open(@params[‘picture_url’]).class
=> Tempfile

You can’t assign a Tempfile to file_column, because then the
extension/mime-type handling is screwed. A tempfile looks like
/tmp/mytemp34222.0. So it’s not recommended. You can copy the
tempfile and reopen as a normal File, or if you’re feeling hackish,
you can change line 46 of lib/file_column.rb to:

if file.is_a?(File) || file.is_a?(Tempfile)

and brave the consequences.


Kyle M.
Chief Technologist
E Factor Media // FN Interactive
[email protected]
1-866-263-3261