image_tag cannot show picture

Dear all

I am new to rails.

In view, I place the following code, but cannot show the picture in the webpage <%= image_tag("green.JPG") %>

However, I can access the picture in this url http://localhost:3000/images/green.JPG

The HTML source code generated <img alt="Green" src="/images/green.JPG.?1228211220" />

I cannot identify the problem. Please help

Thank you very much

Valentino

Do you have the image in the image folder or any other folder?

Also check the extension of that image name(Whether uppercase("green.JPG") or lowercase("green.jpg")). Give correctly.

The HTML source code generated <img alt="Green" src="/images/green.JPG.?1228211220" />

Does

   http://localhost:3000/images/green.JPG.?1228211220

work?

And what is that dot . doing after the JPG?

Next, always use lower case file extensions - jpg. That's just for style, but it helps us diagnose problems...

Phlip wrote:

The HTML source code generated <img alt="Green" src="/images/green.JPG.?1228211220" />

Does

   http://localhost:3000/images/green.JPG.?1228211220

work?

And what is that dot . doing after the JPG?

Next, always use lower case file extensions - jpg. That's just for style, but it helps us diagnose problems...

http://localhost:3000/images/green.JPG.?1228211220 not work, error message as below, I don't know why there is a "." appended after the filename. No route matches "/images/green.JPG." with {:method=>:get}

The image is located at public\images The filename is green.JPG

Thank you for your help. Valentino

http://localhost:3000/images/green.JPG.?1228211220 not work, error message as below, I don't know why there is a "." appended after the filename. No route matches "/images/green.JPG." with {:method=>:get}

The image is located at public\images The filename is green.JPG

Thank you for your help. Valentino

I renamed the file extension to lower case. i.e. green.jpg Not work either <img alt="Dashboard" src="/images/dashboard.jpg.?1228909182" />

Change the extension to lowercase and check it

Sounds to me like that extra . is the problem. The big question is why image_tag adds that extra dot. It shouldn't. Have you looked at the source code for image_tag? You didn't accidentally override it or anything like that?

mcv.

Sounds to me like that extra . is the problem. The big question is why image_tag adds that extra dot. It shouldn't. Have you looked at the source code for image_tag? You didn't accidentally override it or anything like that?

mcv.

Thank you for your help Could you tell me where the source code located?

mcv.

Thank you for your help Could you tell me where the source code located?

I found the source code

      def image_tag(source, options = {})         options.symbolize_keys!

        options[:src] = path_to_image(source)         options[:alt] ||= File.basename(options[:src], '.*').split('.').first.to_s.capitalize         .....SKIP.............

Since I am new to ruby, and I am a green programmer....I cannot figure out the problem. Can you help me?

Thanks alot. Valentino

Since I am new to ruby, and I am a green programmer....I cannot figure out the problem. Can you help me?

Thanks alot. Valentino

I tried the following code, there is also a extra "." <%= image_tag("green.jpg", :alt => "Green") %> I am frustrated. Please help...

Thank you. Valentino

Hello all

I think I identified the problem now

In asset_tag_help.rb, the problem might cause from *****(see below code). I am using Rails 2.1.2, I will try the latest version to see the problem has been fixed. Thanks all

      def image_path(source)         compute_public_path(source, 'images')       end

        def compute_public_path(source, dir, ext = nil, include_host = true)           has_request = @controller.respond_to?(:request)

          cache_key =             if has_request               [ @controller.request.protocol,                 ActionController::Base.asset_host.to_s,                 @controller.request.relative_url_root,                 dir, source, ext, include_host ].join             else               [ ActionController::Base.asset_host.to_s,                 dir, source, ext, include_host ].join             end

          ActionView::Base.computed_public_paths[cache_key] ||=             begin           ***** source += ".#{ext}" if ext && File.extname(source).blank? || File.exist?(File.join(ASSETS_DIR, dir, "#{source}.#{ext}"))

              if source =~ %r{^[-a-z]+://}                 source               else                 source = "/#{dir}/#{source}" unless source[0] == ?/                 if has_request                   unless source =~ %r{^#{@controller.request.relative_url_root}/}                     source = "#{@controller.request.relative_url_root}#{source}"                   end                 end

                rewrite_asset_path(source)               end             end

I think I identified the problem now

Have you also been able to fix it?

In asset_tag_help.rb, the problem might cause from *****(see below code). I am using Rails 2.1.2, I will try the latest version to see the problem has been fixed. Thanks all

     def image_path(source)        compute_public_path(source, 'images')      end

       def compute_public_path(source, dir, ext = nil, include_host = true)          has_request = @controller.respond_to?(:request)

         cache_key =            if has_request              [ @controller.request.protocol,                ActionController::Base.asset_host.to_s,                @controller.request.relative_url_root,                dir, source, ext, include_host ].join            else              [ ActionController::Base.asset_host.to_s,                dir, source, ext, include_host ].join            end

         ActionView::Base.computed_public_paths[cache_key] ||=            begin          ***** source += ".#{ext}" if ext && File.extname(source).blank? || File.exist?(File.join(ASSETS_DIR, dir, "#{source}.#{ext}"))

The thing is, source += ".#{ext}" will only be executed if ext is not nil. In this case, I think ext is nil, so this should be causing the problem.

But if something is really mysterious (and in Rails it often is), then I just add lots of debug statements and see what really happens. puts all the names of methods that are called, and all relevant variables (or just use the debugger, of course!), and see where the dot is added. You may have found a bug in Rails.

             if source =~ %r{^[-a-z]+://}                source              else                source = "/#{dir}/#{source}" unless source[0] == ?/                if has_request                  unless source =~ %r{^#{@controller.request.relative_url_root}/}                    source = "#{@controller.request.relative_url_root}#{source}"                  end                end

               rewrite_asset_path(source)              end            end

All this code is also capable of changing source. I've got no idea what it does, but if you just puts the value of source after each one, you'll see where the dot gets added.

That's the only advice I can give you. Other than that, I'm stumped.

mcv.

Martijn Vos wrote: