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

Deprecate asset fallback #375

Merged
merged 8 commits into from Sep 1, 2016

Conversation

Projects
None yet
4 participants
@schneems
Member

schneems commented Aug 19, 2016

When an asset isn't found the behavior is to pass the string through. For example a valid asset will return a url from pipeline

asset_path("application.js")
# => assets/application-123098udasvi0mnafd.js

While if you make a typo, you won't get an error or anything, it just falls through:

asset_path("app1icati0n.js")
# => "app1icati0n.js"

Hopefully I don't have to elaborate on why this is bad.

This PR is a child PR to one in Rails that will introduce a public_asset_path API.

There are valid reasons for not using the asset pipeline, if you have a purely static asset in the public folder or if you want to link to a static URL in your assets somewhere it makes sense to declare that intention. Eventually we will replace the behavior of the deprecation with an exception so people don't lose hours of their to typos.

We only emit the deprecation when a public_ api is available in Rails. This means that sprockets-rails can still be used in a backwards compatible manner.

Deprecate asset fallback
When an asset isn't found the behavior is to pass the string through. For example a valid asset will return a url from pipeline

```
asset_path("application.js")
# => assets/application-123098udasvi0mnafd.js
```

While if you make a typo, you won't get an error or anything, it just falls through:

```
asset_path("app1icati0n.js")
# => "app1icati0n.js"
```

Hopefully I don't have to elaborate on why this is bad.

This PR is a child PR to one in Rails that will introduce a `public_asset_path` API.

There are valid reasons for not using the asset pipeline, if you have a purely static asset in the public folder or if you want to link to a static URL in your assets somewhere it makes sense to declare that intention. Eventually we will replace the behavior of the deprecation with an exception so people don't lose hours of their to typos.

We only emit the deprecation when a `public_` api is available in Rails. This means that sprockets-rails can still be used in a backwards compatible manner.
@schneems

This comment has been minimized.

Show comment
Hide comment
@schneems

schneems Aug 19, 2016

Member

The Rails PR is rails/rails#26226

Member

schneems commented Aug 19, 2016

The Rails PR is rails/rails#26226

schneems added some commits Aug 20, 2016

Better way to find deprecated method location
Instead of relying on hard coded indexes, we can look through the called method stack backwards (i.e. the first method called will be the first in the list). If it has a suffix for one of our APIs, then we check to see if there exists a `public_` prefix on the view, if it does it's the first method called that can be deprecated so we point to that.
public_* API is not desired
Use `public_folder: true` instead.
public_* API is not desired
- Use `public_folder: true` instead.
- Allow configurable deprecation/error behavior via **`config.assets.unknown_asset_fallback`**

When set to a truthy value, the a result will be returned even if the requested asset is not found in the asset pipeline. When set to `false` it will raise an error.
@@ -6,6 +6,7 @@
module Sprockets
module Rails
module Helper
class AssetNotFound < StandardError; end

This comment has been minimized.

@kaspth

kaspth Aug 30, 2016

Member

Shouldn't we add a newline after this class definition?

@kaspth

kaspth Aug 30, 2016

Member

Shouldn't we add a newline after this class definition?

This comment has been minimized.

@schneems

schneems Aug 31, 2016

Member

done

@schneems

schneems Aug 31, 2016

Member

done

Show outdated Hide outdated README.md

schneems added some commits Aug 31, 2016

@kaspth

This comment has been minimized.

Show comment
Hide comment
@kaspth

kaspth Aug 31, 2016

Member

Does @matthewd's comment about caller_locations stand? Otherwise :shipit: 👏

Member

kaspth commented Aug 31, 2016

Does @matthewd's comment about caller_locations stand? Otherwise :shipit: 👏

@schneems schneems merged commit e3dc15c into master Sep 1, 2016

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@rafaelfranca rafaelfranca deleted the schneems/deprecate-fallback-behavior branch Aug 31, 2017

@rlue

This comment has been minimized.

Show comment
Hide comment
@rlue

rlue Jan 6, 2018

I know it's been a long time since this PR was merged. Is there any chance we could get an update to the section of the Rails Guides that addresses asset fallback?

I'd be glad to submit a PR with the approval of the team (but otherwise, I'm reluctant to spend any time on it).

rlue commented Jan 6, 2018

I know it's been a long time since this PR was merged. Is there any chance we could get an update to the section of the Rails Guides that addresses asset fallback?

I'd be glad to submit a PR with the approval of the team (but otherwise, I'm reluctant to spend any time on it).

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