_photo_shout partial code

I’m a bit confused as to what everything in this line does:

<%= link_to image_tag(photo_shout.image.url(:shout)), photo_shout.image.url %>

Mainly the …url(:shout) and photo_shout.image.url parts.

I understand what photo_shout.image is pulling but where does the ‘url’ part come from? It’s not an attribute on the model. And is …url(:shout) referring to the url of the shout object? If so where is it getting that url from?


The url is something that the Paperclip gem provides.

You then are passing a ‘style’ as an argument to the url method so paperclip knows what style you want your image to return. You defined the shout style in your PhotoShout model:

class PhotoShout < ActiveRecord::Base
  has_attached_file :image, styles: {
    shout: "200x200>"

You could also use:

<%= image_tag photo_shout.image.url %>
<%= image_tag photo_shout.image.url(:medium) %>
<%= image_tag photo_shout.image.url(:thumb) %>

Try it out in the console on a PhotoShout and see the path it’s returning.

To be clear, the different arguments will let you see how it transforms the path returned, but for it to actually work you’d have to add those styles into your model, e.g.

class PhotoShout < ActiveRecord::Base
  has_attached_file :image, styles: {
    shout: "200x200>",
    medium: "300x300",
    thumb: "100x100"

Got it. Thank you, kind sir.