开发者

"Ruby on rails" fetching images one by one specifying different sizes

I am fetching the images from table called galleries. The field include as id, user_id, pic. While fetching the images from this table I need to specify each image in different sizes. All I know is:

<% @us.each do |p| %>

<%= image_tag(p.pics, :size =>"150x300"), :class => "me" %>

<% end %>

This will fetch all 开发者_StackOverflow中文版the images from that table od same size.

How to fetch the images of different sizes? Example in html code:

> <img class="me" src="/images/DSC01145.gif" width="200px"
> height="450px"/>  
> 
> <img class="me" src="/images/DSC01140.gif" width="100px"
> height="200px"/>  
> 
> <img class="me" src="/images/DSC01074.gif" width="100px"
> height="125px"/>  
> 
> <img class="me" src="/images/22.gif" width="175px" height="350px"/>

Thanks


Check out the gem paperclip its great for storing images, and simple to add different size images. Generally people use S3 + Paperclip.

Paperclip


I got the answer for the above....

As the images are always 3 in number, So I am writing in view as:

 <% a = @us[0] %>   
 <% b = @us[1] %>  
<% c = @us[2] %>   
<%= image_tag(a.gal_pics, :size =>"150x300", :class =>"me") %>  
<%= image_tag(b.gal_pics, :size =>"200x450", :class =>"me") %>  
<%= image_tag(c.gal_pics, :size =>"100x200", :class =>"me") %`

Thanks

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜