Linked assets creates broken link


(Danny) #1

Continuing the discussion from Broken Images Under "Media", also unable to install v10:

Hi,
I’m not sure if this is still caused by my environment. I installed imagemagick on Ubuntu 16.04 and I have a node like this:

class Video < PushType::Node
  field :thumbnail_id, :asset
end

In my view I want to display that image like so:

<%= image_tag media_path(item.thumbnail, :small), class: 'img-responsive' %>

Which does not work. My browser displays a broken image link.

<img class="img-responsive" src="/media/84a87d1a-e37f-4121-9d62-a8d7f0592a90.small" alt="84a87d1a e37f 4121 9d62 a8d7f0592a90">

I did not change the default dragonfly configuration and imagemagick is installed.
For some reason calling `item.thumbnail.file_uid’ works but its probably a bad hack.

<%= image_tag media_path(item.thumbnail.file_uid, style: :large), class: 'img-responsive' %>

(Aaron Russell) #2

In your example above:

Can you try passing the second argument to media_path as a hash, rather than a symbol as above. eg:

media_path(item.thumbnail, style: :small)

(Danny) #3

That was an initial oversight. I did try passing it as a hash without any luck.

<%= image_tag media_path(video.thumbnail, style: :small), class: 'img-responsive' %>

(Aaron Russell) #4

Thats a bug then. Should work how you’d expect in that example.

Can you confirm exactly what the resulting URL is from:

 media_path(video.thumbnail, style: :small)

(It shouldn’t end in “.small” if the second argument is a hash.)


(Danny) #5

This code

media_path(video.thumbnail, style: :small) 

Gives

/media/f7fcccc1-58a0-4748-b061-6119211e00fb?style=small

To avoid a possible miscommunication:

My question is based on media_path(item.thumbnail, :small) and the generated link ends in .small.

The corrected version (using a hash), generates a link ending in style=small. The link however does not work. The image is displayed fine on the backend.


(Aaron Russell) #6

Have raised a bug for this.

In the meantime, use the example where you are passing in the file_uid. That’s the way it always used to work, it’s not a hack - just a bit more verbose.

Can I ask, what version of Rails are you using - is it 4 or 5? - either post here or in the github issue. Thanks


(Danny) #7

Rails 4.

Should be over min character now.


(Aaron Russell) #8

And are you definitely on the latest PushType (0.10.2)?

This issue has come up before and was fixed relatively recently, so just checking.


(Danny) #9

I started using PushType a few days ago and my gemfile contains this line:

gem 'push_type'

My gemfile.lock says push_type (0.8.2). I don’t know why bundler installed an outdated version.

I was kinda proud I found a bug. Suppose you can close that issue now! :smile:


(Aaron Russell) #10

Wow that’s a few versions out. Definitely upgrade if you can!

Lets us know if you still have issues after upgrading, but I think that’ll sort it.