Use image_path instead of asset_path in readme

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.
This commit is contained in:
Janko Marohnić
2015-01-24 04:23:36 +01:00
parent b841e20394
commit 9308a10b52
2 changed files with 2 additions and 2 deletions

View File

@@ -57,7 +57,7 @@ module EmojiHelper
def emojify(content)
h(content).to_str.gsub(/:([\w+-]+):/) do |match|
if emoji = Emoji.find_by_alias($1)
%(<img alt="#$1" src="#{asset_path("emoji/#{emoji.image_filename}")}" style="vertical-align:middle" width="20" height="20" />)
%(<img alt="#$1" src="#{image_path("emoji/#{emoji.image_filename}")}" style="vertical-align:middle" width="20" height="20" />)
else
match
end

View File

@@ -18,7 +18,7 @@ class DocumentationTest < TestCase
str.gsub('<', '&lt;').gsub('>', '&gt;')
end
def self.asset_path(img)
def self.image_path(img)
"/images/#{img}?123"
end
end