SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jun 2008
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    trouble displaying multiple embedded images

    Hi,

    I am trying to display a gallery of images sourced from flickr (or wherever). The URLs are stored in the database and called as either a single image along with other entered info or as a group for gallery purposes.

    I have the individual image view going fine with:
    <img src="<%=h @piece.image_url -%>" alt="<%=h @piece.piece_title -%>" />

    but, trying to get the gallery to show up, I first tried:
    <codee>
    <% for piece in @pieces -%>
    <%= link_to image_tag("@piece.image_url", :border=>0), :action => 'show', :id => piece %>
    <% end %>
    <%= will_paginate @pieces %>
    </code>
    and only see little question mark place holders and the paginated 'footer' - since I really wanted thumbnails though, I tried:
    <codee>
    <% for piece in @pieces -%>
    <%= "<img src=(h @piece.image_url) width=20% height=20% />" %>
    <% end %>
    <%= will_paginate @pieces %>
    </codee>
    and it gives me correctly sized boxes with the little question marks and the paginated 'footer' but also when I navigate to another page, say 2, it doesn't make page 1 or 'previous' a navigable link.

    I'm wondering if I have to preload the images into cache, but how?

    Any suggestions?
    Thanks

  2. #2
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The error in your first code snippet is the quotation marks around @piece.image_url. Fix: remove the quotation marks.

    The error in your second snippet is that you're just outputting the string "<img src=(h @piece.image_url) width=20&#37; height=20% />". So you're not executing (h @piece.image_url). Fix: Remove <%= %> around the string and put <%= %> inside the img tag like this:

    Code:
    <img src=<%=h @piece.image_url %> width=20% height=20% />
    (note that this does not link to the image)

    The solution that I like most is using the image_tag helper (your first snippet):

    Code:
    <% for piece in @pieces -%>
    <%= link_to image_tag(@piece.image_url, :size => "100x100", :border=>0), :action => 'show', :id => piece %>
    <% end %>

  3. #3
    SitePoint Member
    Join Date
    Jun 2008
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    okay, thanks for that... even though I couldn't get yours to work as is, I nixed the @ and it's fine... thanks


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •