开发者

My app cannot find my images' paths

开发者 https://www.devze.com 2023-03-18 16:39 出处:网络
I have my images stored in /rubyprograms/search/public/urlimages. I checked through my terminal to make sure that path is there and that all of the images are inside it. I link to the images, for exam

I have my images stored in /rubyprograms/search/public/urlimages. I checked through my terminal to make sure that path is there and that all of the images are inside it. I link to the images, for example, at this path: /­rubyprograms/­search/­public/­urlimages/­2173513720.­jpg but my app cannot seem to find the image. For example, this is an error in my logs:

Started GET "/rubyprograms/search/public/urlimages/2173486240.jpg" for 127.0.0.1 at Thu Jul 07 21:34:23 -0700 2011

Ac开发者_Go百科tionController::RoutingError (No route matches "/rubyprograms/search/public/urlimages/2173486240.jpg"):

However I know the images are there at that route. Why is this happening?


If your app is in /rubyprograms/search, the public/ directory will be used as the root directory for all non-Rails requests.

Because of this, the correct path to the images would be /urlimages/2173486240.jpg.

Rails has a handy helper for images, called image_tag, which essentially creates image tags for you. The usage is:

<%= image_tag('2173486240.jpg') %>
# will create <img src="/images/2173486240.jpg" alt="" />

Please note that this will create the entire html tag, and assume that you have your images in public/images/.


Public has to be in the root directory.

`/rubyprograms/search/public/urlimages/2173486240.jpg`

Needs to be

`/rubyprograms/public/urlimages/2173486240.jpg`

If you wand to follow COC.

0

精彩评论

暂无评论...
验证码 换一张
取 消