Apache + Displaying images

Hi,
I’m new to Rails, sorry if I’m repeating the question, but I couldn’t
find a solution for my problem so far :frowning:

I’m using Apache2 as the web server of my Rails application. I keep my
images in public/images and tried inserting images to the page like
this;

<%= image_tag “rails.png” %>

But the image is not displayed on the browser. Can anyone pleeeeese
point out the problem?

I could do this using WEBrick though.

-Umesha

Umesha wrote:

Hi,
I’m new to Rails, sorry if I’m repeating the question, but I couldn’t
find a solution for my problem so far :frowning:

I’m using Apache2 as the web server of my Rails application. I keep my
images in public/images and tried inserting images to the page like

“public” is your webroot… that’s where apache starts looking for stuff
to serve.
“images” is a subdirectory of “public”.

<%= image_tag “rails.png” %>

This is going to make an image tag with src=“rails.png”… which, since
you didn’t specify
a path, means apache is going to look in your webroot… or the “public”
directory.

In other words, try “/images/rails.png”.

b

Thanks a lot Ben, but still it doesn’t work. When I view the page source
of the browser, it correctly shows as,
Rails
but still the image is not visible on any of the browsers.

Ben M. wrote:

Umesha wrote:

Hi,
I’m new to Rails, sorry if I’m repeating the question, but I couldn’t
find a solution for my problem so far :frowning:

I’m using Apache2 as the web server of my Rails application. I keep my
images in public/images and tried inserting images to the page like

“public” is your webroot… that’s where apache starts looking for stuff
to serve.
“images” is a subdirectory of “public”.

<%= image_tag “rails.png” %>

This is going to make an image tag with src=“rails.png”… which, since
you didn’t specify
a path, means apache is going to look in your webroot… or the “public”
directory.

In other words, try “/images/rails.png”.

b

Well you’ve got me stumped then… you’re sure it’s in the same app
directory?

b

Try to right click on the missing image, choose properties (if your
using
firefox) and see what path is beeing used.
You should be able to figure out why it is not displayed.

Are you on a *nix platform? Is the file named “rails.png” exactly? or
is it
“Rails.png”? CaSe matters in *nix.

~ Ben

Ben M. wrote:

Well you’ve got me stumped then… you’re sure it’s in the same app
directory?

b

Yes, the image (rails.png) is placed in
‘C:\Program Files\Apache
Group\Apache2\htdocs\apache_rails\public\images’ where my application
folder is named as ‘apache_rails’.

And I’ve specified the Document root of Apache as
‘DocumentRoot “C:/Program Files/Apache
Group/Apache2/htdocs/apache_rails/public”’ in httpd.conf file

For the simplicity I have only following 2 lines in the relavent view
file.

Displaying an image

<%= image_tag "/images/rails.png" %>

But once it is viewed from a browser, only the heading is displayed with
the word ‘Rails’ under that and it’s page source is,

Displaying an image

Rails

But once I do the same thing in a application using WEBrick server with
the same view file and image placed in it’s ‘public\images’, the image
is visible. Also it’s page source is same as above.

I really cannot find what’s the problem. :frowning:

-umesha

What URL are you using to access the app in Apache?

Joshua W. wrote:

What URL are you using to access the app in Apache?

I use ‘http://localhost/friend/test_pic’ to access that page.

I’ve defined the method ‘test_pic’ in ‘FriendController’ as below:

class FriendController < ApplicationController
def test_pic

end

end

And the ‘test_pic.rhtml’ has only these 2 lines:

Displaying an image

<%= image_tag "/images/rails.png" %>

I still can’t figure out why the image is not displayed on the browser.

Thanks,
Umesha

On 3/13/06, Umesha P. [email protected] wrote:

I use ‘http://localhost/friend/test_pic’ to access that page.
[…]
And the ‘test_pic.rhtml’ has only these 2 lines:

Displaying an image

<%= image_tag "/images/rails.png" %>

I still can’t figure out why the image is not displayed on the browser.

Is the image at “http://localhost/friend/images/rails.png”, or "
http://localhost/images/rails.png" ?

I’m guessing you want the former, but the code you’re using is
generating
the latter.

– Joshua