Displaying images from database

I’m saving images to a database when uploaded, and I’m trying to display
the images back out in the views. I can get this to work, but it’s not
very consistent… Here’s what I’m doing:

<%= image_tag(url_for(:controller=>“picture”, :action=>“show”,
:id=>@house.picture_id),:alt=>"")%>

Right off, it doesn’t show the images. But eventually it does, like if
I interact with the database again, or re-upload an image, they all seem
to work. This seems to be my problem, when right-clicking on the
properties of the image, this is the url:

/picture/show/1.png?

And it should be:

/picture/show/1

How come this is appending “.png?” to the end of my image? Should this
be doing this? Please help, as the images HAVE to show up, and I’ve
tried everything I can think of. Thanks!

ryan wrote:

I’m saving images to a database when uploaded, and I’m trying to display
the images back out in the views. I can get this to work, but it’s not
very consistent… Here’s what I’m doing:

<%= image_tag(url_for(:controller=>“picture”, :action=>“show”,
:id=>@house.picture_id),:alt=>“”)%>

Right off, it doesn’t show the images. But eventually it does, like if
I interact with the database again, or re-upload an image, they all seem
to work. This seems to be my problem, when right-clicking on the
properties of the image, this is the url:

/picture/show/1.png?

And it should be:

/picture/show/1

How come this is appending “.png?” to the end of my image? Should this
be doing this? Please help, as the images HAVE to show up, and I’ve
tried everything I can think of. Thanks!

The image_tag helper will append .png if there is no extension in the
url since it thinks all of your image should be files.

The best way around this is create a custom route that looks like an
image file.

map.picture ‘pictures/show/:id/imge.jpg’,
:controller => :pictures, :action => 'show

or on edge rails:

map.picture ‘pictures/show/:id.jpg’
:controller => :pictures, :action => 'show

Then you can:

<%= image_tag(picture_url(:id => 1)) %>

And all should be dandy.

Also look into the Flex Image plugin as it will make the reading and
writing of image to your database super easy.

http://www.agilewebdevelopment.com/plugins/fleximage

Is there any way to emulate that :id.jpg routing functionality without
edge rails? I can’t justify edge for only that, but would really like
.jpg extensions on the images.

Thanks,
Chad

On Nov 20, 11:18 pm, Alex W. [email protected]

Chad wrote:

Is there any way to emulate that :id.jpg routing functionality without
edge rails? I can’t justify edge for only that, but would really like
.jpg extensions on the images.

Thanks,
Chad

On Nov 20, 11:18 pm, Alex W. [email protected]

You can do the first option I suggested:

map.picture ‘pictures/show/:id/image.jpg’,
:controller => :pictures, :action => 'show

it will just give urls like: /pictures/show/1/image.jpg

instead my second example on edge: /pictures/show/1.jpg

It works without edge rails fine, its just not quite as concise.