[Rails] passing size for image_tag to view via model
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.
Is there any?
Thanks in advance!
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home