Cada bucle Haml?

Tengo esta 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

Porque @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

Pero esto genera region_city_attachment_path which is not correct. The first each loop a variable store the correct value, but how can I reach la primera a variable en el segundo each ¿círculo?

preguntado el 29 de julio de 12 a las 23:07

3 Respuestas

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

Respondido 29 Jul 12, 23:07

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

Respondido el 25 de enero de 16 a las 20:01

Just don't use the same name for both of them, and everything will turn out fine.

Respondido 29 Jul 12, 23:07

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.