Hi group,
I have a problem with an image_tag. It's rather complicated and I
can't find an easy solution.
I have a model called "Medium" which can hold a paperclip file
attachment or a remote url. I want to treat all media equally from my
view, so if I need a preview picture, I use get_picture(size). This
matches with paperclip's autogenerated thumbnails and everything is
fine.
In case I have a youtube-video in my remote link, things are starting
to get ugly. Fortunately youtube autogenerates preview pictures from
the videos, and I am totally okay with these, the only problem is that
I can't resize them properly without busting my view.
So what I need is a possibility to say my get_picture(size)-method
something like
case size
when :large
return youtube_picture.png, size => "1000x1000"
when :small
return youtube_picture.png, size => "5x5"
end
From the view, I want to call
<%= image_tag medium.get_picture(:small) %>
and I don't want to pass in the parameter on view side, because that
would be very repetitive.
My workaround was to make a method "get_size(size)", so that I can use
<%= image_tag medium.get_picture:small, :size =>
medium.get_size(:small) %>
but that's ugly and there has to be a better way to do this.
Yeah, that is the solution I found, but I don't think it's pretty.
Isn't there a possibility to make this better, like link_to
method_returnvalue or something?
if I call image_tag without the :size param, it can happen that, if I
have images of different sizes, they bust my view because they all are
of different sizes. If i call :size => "xxy" in every line of the code
where I want a picture to be force-resized, i repeat myself over and
over, and in the second I get the idea of changing one picture's
dimension, I'm in trouble.
So what I want is my view to say to my model "hi, i want your image
tag" and my model to say "here it is, oh, btw, it has a fixed
resolution of 250x150 px, display this, kkthxbb"