Search code examples
ruby-on-railsminimagick

Include resize in image_tag with id


I use mini_magick for resize image.

model

def large input
    return self.images[input].variant(resize: '400x400!').processed
end

But how to include resize in this image_tag :

<%= image_tag(projet.images[0]) if projet.images.length > 0 %>

That's how i usually use it:

<% ([email protected]).each do |image| %>
    <%= image_tag(@projet.large(image))%>
<% end %>

But today i would like to use it for an image_tag with id.

I try :

<%= image_tag(projet.images[0].variant(resize_to_fit: [400, 400])) if projet.images.length > 0 %>

Thanks for your help.


Solution

  • I find a solution :

     <%= image_tag url_for(projet.images[0].variant(resize: "400x400")) if projet.images.length > 0 %>
    

    with class :

    <%= image_tag(url_for(projet.images[0].variant(resize: "400x400")), class:"background") if projet.images.length > 0 %>