I have this each loop: (haml) 
- @deals.each do |a|
     .slide
        %a{:href => "#"}
         - a.attachments.each do |a|
           = image_tag(a.file.url, :height =>"325px", :width =>"650px" )
            .caption{:style => "bottom:0"} 
              = a.description
Because @deals is combined query of 3 tables (models) I use polymorphic_path to generate the links of the images.
- @deals.each do |a|
     .slide
        %a{:href => "#"}
         - a.attachments.each do |a|
           = image_tag(a.file.url, :height =>"325px", :width =>"650px" ), polymorphic_path(@region, @city, a)
            .caption{:style => "bottom:0"} 
              = a.description
But this generates region_city_attachment_path which is not correct. The first each loop a variable store the correct value, but how can I reach the first a variable in the second each loop?
Just give it another name.
- @deals.each do |a|
     .slide
        %a{:href => "#"}
         - a.attachments.each do |b|
           = image_tag(a.file.url, :height =>"325px", :width =>"650px" ), polymorphic_path(@region, @city, b)
            .caption{:style => "bottom:0"} 
              = a.description
                        you should be more clear when using variable names, do something like
- @deals.each do |deal|
  .slide
    %a{:href => "#"}
      - deal.attachments.each do |attachment|
        ..
it's a really bad practice to use names such as "a"/"b"/"x" when you can write a much more readable code
Just don't use the same name for both of them, and everything will turn out fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With