Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

image_path without extension #35651

Closed
gadikotamohan opened this issue Mar 17, 2019 · 14 comments
Closed

image_path without extension #35651

gadikotamohan opened this issue Mar 17, 2019 · 14 comments

Comments

@gadikotamohan
Copy link

gadikotamohan commented Mar 17, 2019

Steps to reproduce

  • Add a image helper as follows

<%= image_tag image_path("sample/olivia"), class: 'img img-raised' %>
and run in development and it works without any errors. But if I run in production I would get

F, [2019-03-17T18:36:37.568202 #25602] FATAL -- : [1c06c250-3a3e-46f4-8dbb-10686d28d26f] ActionView::Template::Error (The asset "sample/olivia" is not present in the asset pipeline.):

Expected behavior

  • Should set actual path with digest / find the asset path with give name.

Actual behavior

  • Throws internal server error

System configuration

Ruby version: 2.5.3

Rails version: 5.2.2

@arvind02
Copy link

I hope you meant

Rails Version - 5.2.2
Ruby Version - 2.5.3

@himanshu-myupchar
Copy link

@gadikotamohan have you precompiled the assets?

@gadikotamohan
Copy link
Author

@gadikotamohan have you precompiled the assets?

Yes, even asset those files in the asset pipeline as well.

@gadikotamohan
Copy link
Author

I hope you meant

Rails Version - 5.2.2
Ruby Version - 2.5.3

yes, sorry my bad corrected my post.

@rails-bot
Copy link

rails-bot bot commented Jul 4, 2019

This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails team are limited, and so we are asking for your help.
If you can still reproduce this error on the 5-2-stable branch or on master, please reply with all of the information you have about it in order to keep the issue open.
Thank you for all your contributions.

@rails-bot rails-bot bot added the stale label Jul 4, 2019
@lachlanjc
Copy link
Contributor

To clarify, do you have a file with no extension? Can you say why? If the content type isn’t set correctly, won’t that be an issue for browsers as well?

@rails-bot rails-bot bot removed the stale label Jul 9, 2019
@gadikotamohan
Copy link
Author

@lachlanjc Um.. there need to be consistency of asset url helpers behavior between environment ie; when generating image path in development it is returning correct path but in production mode we get 500 error saying file is not part of asset precompile list.

This can re-produced in https://github.com/gadikotamohan/image_test project

In production mode:
Screenshot 2019-07-10 at 1 35 37 AM

In development mode
Screenshot 2019-07-10 at 1 36 49 AM
Screenshot 2019-07-10 at 1 36 43 AM

@lachlanjc I agree that it doesn't make sense to call image_path without valid extension but behavior of image_path need to be consistent by giving same/similar error even for development.

@Hermosa1127
Copy link

Hermosa1127 commented Aug 4, 2019

Steps to reproduce

  • Add a image helper as follows
    FATAL -- : [1c06c250-3a3e-46f4-8dbb-10686d28d26f] ActionView::Template:: <%= image_tag image_path("sample/olivia"), class: 'img img-raised' %>
    and run in development and it works without any errors. But if I run in production I would get

F, [2019-03-17T18:36:37.568202 #25602] FATAL -- : [1c06c250-3a3e-46f4-8dbb-10686d28d26f] ActionView::Template::Error (The asset "sample/olivia" is not present in the asset pipeline.):

Expected behavior

  • Should set actual path with digest / find the asset path with give name.

Actual behavior

  • Throws internal server error

System configuration

Ruby version: 2.5.3

Rails version: 2.3.5("olivia/sample#"))

{
"offlinePages": [],
"savePageRequests": [
{
"creationTime": "Sun Aug 04 2019 10:18:19 GMT-0500 (Central Daylight Time)",
"id": "4762759857542978660",
"lastAttemptTime": "Wed Dec 31 1969 18:00:00 GMT-0600 (Central Standard Time)",
"namespace": "async_loading",
"onlineUrl": "http://bettermindz.com/",
"originalUrl": "",
"requestOrigin": "",
"status": "Available"
},
).<%= image_tag image_path("sample/olivia"), class: 'img img-raised' %>
).
"creationTime": "Sun Aug 04 2019 10:07:49 GMT-0500 (Central Daylight Time)",
"id": "7096744388757503707",
"lastAttemptTime": "Wed Dec 31 1969 18:00:00 GMT-0600 (Central Standard Time)",
"namespace": "async_loading",
"onlineUrl": "https://github.com/mit-plu/fiat-crypto/blob/master/Authors",
"originalUrl": "",
"requestOrigin": "",
"status": "Available"
},
{
"creationTime": "Sun Aug 04 2019 10:04:50 GMT-0500 (Central Daylight Time)",
"id": "7115742913666514860",
"lastAttemptTime": "Sun Aug 04 2019 10:18:19 GMT-0500 (Central Daylight Time)",
"namespace": "async_loading",
"onlineUrl": "http://chrome.com/",
"originalUrl": "",
"requestOrigin": "",
"status": "Available"
)
)

)

@rails-bot
Copy link

rails-bot bot commented Nov 2, 2019

This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails team are limited, and so we are asking for your help.
If you can still reproduce this error on the 6-0-stable branch or on master, please reply with all of the information you have about it in order to keep the issue open.
Thank you for all your contributions.

@rails-bot rails-bot bot added the stale label Nov 2, 2019
@rails-bot rails-bot bot closed this as completed Nov 9, 2019
@namiwang
Copy link

namiwang commented Aug 25, 2020

We just encountered this issue.

I understand and agree that paths without extensions should not work. But then it's magically-working-in-development becomes a bug and should be warned at least.

@rafaelfranca
Copy link
Member

👍 Please do investigate why there is this discrepancy between environments and open a PR.

@rafaelfranca rafaelfranca reopened this Aug 26, 2020
@rails-bot rails-bot bot removed the stale label Aug 26, 2020
@namiwang
Copy link

Started to jumping into the code and immediately found that path without an extension should work indeed. Now I'm confused.

# image_path("edit") # => "/assets/edit"
# image_path("edit.png") # => "/assets/edit.png"
# image_path("icons/edit.png") # => "/assets/icons/edit.png"
# image_path("/icons/edit.png") # => "/icons/edit.png"
# image_path("http://www.example.com/img/edit.png") # => "http://www.example.com/img/edit.png"

@allenwu1973
Copy link

allenwu1973 commented Sep 17, 2020

I think this is a very well known bug.
rails/sprockets-rails#305
rails/sprockets-rails#403

@namiwang you should be looking at here
https://github.com/rails/sprockets-rails/blob/master/lib/sprockets/rails/helper.rb#L77

@rafaelfranca
This is probably due to the Sprockets::Rails::HelperAssetResolvers::Manifest behavior differs from Sprockets::Rails::HelperAssetResolvers::Environment

if digest is enabled, Sprockets::Rails::HelperAssetResolvers::Manifest simply lookup file hash from a Hash (specificlly, @manifest.assets), so full file name must be supplied, or the asset would be considered missing.

In development mode, file extensions can be omitted, which is done by the logic here (find_matching_path_for_extensions):
https://github.com/rails/sprockets/blob/master/lib/sprockets/path_utils.rb#L236

An old PR suggests enfore extension check in sprockets_rails's asset_path.
https://github.com/rails/sprockets-rails/pull/461/files

I'd like to send in a PR to sprockets_rails,
but since this issue and proposed fix has been ignroed for a long time,
it'd be nice for the core team to suggest the disired direction for the fix.

@rails-bot
Copy link

rails-bot bot commented Dec 16, 2020

This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails team are limited, and so we are asking for your help.
If you can still reproduce this error on the 6-0-stable branch or on master, please reply with all of the information you have about it in order to keep the issue open.
Thank you for all your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants