Skip to content

Use image_path instead of asset_path in readme #69

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

Merged
merged 1 commit into from
Jan 26, 2015

Conversation

janko
Copy link
Contributor

@janko janko commented Jan 24, 2015

In Rails 4.2 using asset_path doesn't work properly, because asset_path I think doesn't do anything except detect cache URLs. With image_path it works for me.

@janko janko changed the title User image_path instead of asset_path in readme Use image_path instead of asset_path in readme Jan 24, 2015
@mislav
Copy link
Contributor

mislav commented Jan 25, 2015

What does asset_path do in Rails 4.2 again exactly?

@janko
Copy link
Contributor Author

janko commented Jan 25, 2015

Basically just prepends "/assets" if the file is found in app/assets directory, and for public/ files it doesn't do anything.

@mislav
Copy link
Contributor

mislav commented Jan 25, 2015

So what stopped working in Rails 4.2?

@janko
Copy link
Contributor Author

janko commented Jan 25, 2015

# Rails 4.1
asset_path "application.js"                     # => /application.js
asset_path "application", type: :javascript     # => /javascripts/application.js
asset_path "application", type: :stylesheet     # => /stylesheets/application.css
asset_path "http://www.example.com/js/xmlhr.js" # => http://www.example.com/js/xmlhr.js
# Rails 4.2
asset_path "application.js"                     # => /assets/application.js
asset_path "application", type: :javascript     # => /assets/application.js
asset_path "application", type: :stylesheet     # => /assets/application.css
asset_path "http://www.example.com/js/xmlhr.js" # => http://www.example.com/js/xmlhr.js

It apparently stopped prepending the "stylesheets/javascripts/images" directory.

@mislav
Copy link
Contributor

mislav commented Jan 25, 2015

How does this affect image assets used for emoji?

@janko
Copy link
Contributor Author

janko commented Jan 25, 2015

The emoji images are copied to public/images/emoji/unicode/ directory. asset_path("emoji/#{emoji.image_filename}") in Rails 4.2 generates the URL path /emoji/unicode/*.png instead of /images/emoji/unicode/*.png.

I don't know what asset_path is then used for exactly, but I always use image_path.

@mislav
Copy link
Contributor

mislav commented Jan 25, 2015

@josh @charliesome Do you know why this would have changed in Rails 4.2?

We're discussing it here for documentation purposes only, but still.

@josh
Copy link
Contributor

josh commented Jan 26, 2015

👍 image_path

@mislav
Copy link
Contributor

mislav commented Jan 26, 2015

@janko-m OK can you amend the commit to add an explanation to the commit message then?

In Rails 4.2 `#asset_path` has changed. Prior to Rails 4.2,
`#asset_path` would search all asset directories, and prepend the
appropriate asset type directory name to the result:

  asset_path("emoji/unicode/<id>.png")
  #=> "/images/emoji/unicode/<id>.png"

However, In Rails 4.2 `#asset_path` doesn't do that anymore, and assumes
that you've specified the correct folder. Since Emoji images are copied
to public/images/emoji/unicode, `#asset_path` would then generate the
wrong URL path:

  asset_path("emoji/unicode/<id>.png")
  #=> "/emoji/unicode/<id>.png"

Using `#image_path` fixes that, because that method looks specifically
for images/ folder, so it will find the Emoji images.
@janko
Copy link
Contributor Author

janko commented Jan 26, 2015

Amended.

@mislav
Copy link
Contributor

mislav commented Jan 26, 2015

Perfect, thanks bro
*fistbump* 👊

mislav added a commit that referenced this pull request Jan 26, 2015
Use image_path instead of asset_path in readme
@mislav mislav merged commit 4e6ce27 into github:master Jan 26, 2015
@janko janko deleted the patch-1 branch January 26, 2015 23:31
@janko
Copy link
Contributor Author

janko commented Jan 27, 2015

Bro five
Oh no, I high fived to your fist bump. I'll get it right the next time.

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

Successfully merging this pull request may close these issues.

4 participants