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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
How about something like this:
attr_reader :size
Sizes = {:small => ''5x5''
:large => ''1000x1000''}
def get_preview(size)
...
...
end
def small_preview
@small ||= get_preview(Sizes[:small])
@size = Sizes[:small]
end
def large_preview
@large ||= get_preview(Sizes[:large])
@size = Sizes[:large]
end
<%= image_tag medium.small_preview, :size => medium.size %>
--
Posted via http://www.ruby-forum.com/.
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi, thanks for your reply!> <%= image_tag medium.small_preview, :size => medium.size %>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 you say no, I will cry :) -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I don''t know enough about rails to say no. But I also don''t understand what you are hoping for. -- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi, 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" Hope I made it clearer now? :) Thanks for your help anyway On Aug 4, 3:40 pm, 7stud -- <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I don''t know enough about rails to say no. But I also don''t understand > what you are hoping for. > > -- > Posted viahttp://www.ruby-forum.com/.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.
On 3 August 2011 17:21, manavortex <ewa.baumgarten-VvJRU8JoNjXQT0dZR+AlfA@public.gmane.org> wrote:> 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.Use a view helper to replace that code with a call to your helper <%= auto_size_image_tag( medium ) %> Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.