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

Rails 4.2 image_tag no longer accepts Paperclip::Attachment correctly #16911

Closed
afn opened this issue Sep 13, 2014 · 1 comment
Closed

Rails 4.2 image_tag no longer accepts Paperclip::Attachment correctly #16911

afn opened this issue Sep 13, 2014 · 1 comment
Milestone

Comments

@afn
Copy link
Contributor

afn commented Sep 13, 2014

There's a subtle change in asset_path between Rails 4.1 and 4.2 which breaks the ability to pass Paperclip::Attachment objects to image_tag.

It changed from:

source = source.to_s
return "" unless source.present?

to:

return "" unless source.present?
source = source.to_s

Suppose you have a model like:

class User < ActiveRecord::Base
  has_attached_file :avatar, default_url: 'avatar_missing.png'
end

If a user doesn't have an avatar, then user.avatar.present? will be false but user.avatar.to_s returns avatar_missing.png. Therefore, image_tag current_user.avatar used to behave as expected:

<img alt="Avatar missing" src="/images/avatar_missing.png" />

but now it sets the src attribute of the img to "":

<img src="" />
@seuros seuros added this to the 4.2.0 milestone Sep 13, 2014
matthewd added a commit that referenced this issue Sep 13, 2014
…_path"

This reverts commit 21ec7fe.

Per #16911, there's actually a good reason for a "blank" value to have a
useful `to_s` here. So let's also add some tests to prove that.
@matthewd
Copy link
Member

Fixed in 457c876.

Thanks for catching this!

trungpham pushed a commit to trungpham/rails that referenced this issue Sep 18, 2014
…asset_path"

This reverts commit 21ec7fe.

Per rails#16911, there's actually a good reason for a "blank" value to have a
useful `to_s` here. So let's also add some tests to prove that.
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

No branches or pull requests

3 participants