Editing FlexImage filenames

I’m using FlexImage to upload files, and I want to also be able to go
back and edit the file.

So an edit operation would produce the name of the file that was
uploaded, and produce a thumbnail for visual reference, with the ability
to delete this image entirely, or to change it’s uploaded path/image.

Would I need to add a column to my Images table to save the uploaded
path, and then populate the file_field with that value? (Is there even a
way to populate the file_field with a previous value?)

Any thoughts or experiences would be time saving and appreciated.

Matt

OK. different question, but I’ll keep it in the same thread, since Its
FlexImage related.

What is the best way to display multiple images that are already in the
database from a FlexImage upload?

I have multiple photos that belong to one listing (one-to-many), I was
going to do a render_flex_image() on one of the images, but I’m getting
an error back that it doesn’t like the datatype I’m handing in (Array)

@listing = Listing.find(9)
@image = Photo.find(:all,
:conditions => [ “listing_id = ?”, @listing.id ] )

@image is an array of 1 image

render_flex_image(@image)
–> undefined method `data_field’ for Array:Class

If I use the following instead:
render_flex_image(@image[0])

I don’t get an error, and I get the image, but without any layout.

What am I doing wrong?

Ultimately, I just want to display numerous photos on the same page.

Matt

matt wrote:

I’m using FlexImage to upload files, and I want to also be able to go
back and edit the file.

So an edit operation would produce the name of the file that was
uploaded, and produce a thumbnail for visual reference, with the ability
to delete this image entirely, or to change it’s uploaded path/image.

The thumbnail would be created when it’s requested, rather than at
upload. To create the thumbnail when it’s uploaded, use file_column
instead.

Would I need to add a column to my Images table to save the uploaded
path, and then populate the file_field with that value? (Is there even a
way to populate the file_field with a previous value?)

The filestore is defined once for the entire class. It’s not really
designed to start moving the stored images around in various places on
the filesystem. You will have to roll your own solution for that.

I’m not really getting what you are trying to accomplish here. Would it
make more sense to have a dynamic route that simply requests the proper
image based on some attribute rather than physically moving the images
around the filesystem of your server?

What is the best way to display multiple images that are already in the
database from a FlexImage upload?

Remember your HTTP basics here. 1 request from the browser, 1 response
from the server. You can’t send multiple responses to the same request.
To put mulptiple images on a page, simply put the html for multiple
image tags on that page. Then the browser will send a specific request
for each image

<% @item.images.each do |img| %>
<%= image_tag :action => ‘image’, :id => img %>
<% end %>

Then your controller gets a request for each image, with that image’s
id, then sends the image data.

Can render_flex_image() take an Array of images?

No. Since you can only send 1 response per request, you can only render
1 image per request.

Can render_flex_image() take an Array of images?

What is the proper usage/intent of render_flex_image() ?

When I use it, it only displays an image, no layout, is that the proper
intent?

matt wrote:

Can render_flex_image() take an Array of images?

No. Since you can only send 1 response per request, you can only render
1 image per request.

I think this is the crux of my mis-understanding.

What does render_flex_image do?

Normally, rails will send text data in response to a request, in the
form of HTML. This is created from executing a .rhtml file. The result
is text data and has a content type of text/html.

Now assuming:

def foo
@foo = MyImage.find(1)
render_flex_image(@foo)
end

without the render_flex_image, rails would try to run foo.rhtml to
create the response data. Since there is no template by that name, we
don’t want that to happen.

What does render_flex_image(@foo) do then? It tell rails to send the
image data (from the object @foo) as the response instead of sending the
result of a .rhtml template file. The browser receives binary image
data with a content type of image/jpeg.

Short version: It makes rails send binary image/jpeg data rather
text/html data.

Can render_flex_image() take an Array of images?

No. Since you can only send 1 response per request, you can only render
1 image per request.

I think this is the crux of my mis-understanding.

What does render_flex_image do?

On Wed, 2007-01-03 at 23:22 +0100, Alex W. wrote:

Normally, rails will send text data in response to a request, in the
without the render_flex_image, rails would try to run foo.rhtml to

Thanks for the extended description, I think his explains why the view
source was garbled. :slight_smile:

So render_flex_image really is intended to only display a single image
in the browser, with no extra markup ?

So if I wanted to display an array of images in a specified layout, I
could use something like:

render :action => ‘display_images_with_layout’

and then have a display_images_with_layout.rhtml file that loops through
the images per your previous post?

Thanks

Matt

matt wrote:

On Wed, 2007-01-03 at 23:22 +0100, Alex W. wrote:

Normally, rails will send text data in response to a request, in the
without the render_flex_image, rails would try to run foo.rhtml to

Thanks for the extended description, I think his explains why the view
source was garbled. :slight_smile:

Image data in a text viewer really isn’t very pretty

So render_flex_image really is intended to only display a single image
in the browser, with no extra markup ?

Right. In fact you CAN’T mix markup with image data. The browser
expects to get html from the first request and then get image data for
an tags it finds in that html. If there is any markup
along wiht that image data, the browser will think it’s an invalid
format and wont display the image.

So if I wanted to display an array of images in a specified layout, I
could use something like:

render :action => ‘display_images_with_layout’

and then have a display_images_with_layout.rhtml file that loops through
the images per your previous post?

Here’s a full example, assume Foo has_many :my_images

#controller
def show
@foo = Foo.find(params[:id])
end

def image
@image = MyImage.find(params[:id])
render_flex_image(@image)
end

#show.rhtml

Images for this foo

<% @foo.images.each do |image| %> <%= image_tag url_for(:action => 'image', :id => image) %> <% end %>

This creates html like:

Images for this foo

So the browser then gets the image at each of those urls. And your
browser doesn’t care if those image urls are static files served by the
webserver or dynamically created by rails.