문제

여기에 하나의 앵커 만 출력하고 싶습니다. current_page가 배열에 있으면 2 (.html 및 -nf.html)를 얻습니다. 배열에 있지 않으면 배열에 항목이있는만큼 많은 앵커를 얻습니다.

나는 사용 중입니다 정적.

- if page_options[:current_index] < page_options[:total_index] && page_options[:current_index] > 0

    // loop through the pre-flash array and if current page matches, add -nf
    - page_options[:pre_flash] = ['string_one-nf', 'string_two-nf', 'string_three-nf']
    - page_options[:pre_flash].each do |each_string|

        - if current_page.include? each_string
            %li 
                %a{ :href => "page#{page_options[:current_index]}-nf.html", :class => "next" }
                    Next
        - else
            %li
                %a{ :href => "page#{page_options[:current_index]}.html", :class => "next" }
                    Next
도움이 되었습니까?

해결책

unless current_page.include? the_string

편집하다:

첫 번째 발견이 유일한 사람이 되려면 각 루프를 깨뜨릴 수 있습니다. 그러나 이제는 어레이를 반복하고 첫 번째 요소를 끊고있는 일이 발생하더라도 조금 이상하게 보입니다. 내가 당신의 문제를 전혀 해결하고 있습니까?

options[:pre_flash] = ['string_one-nf', 'string_two-nf', 'string_three-nf']
page_options[:pre_flash].each do |each_string|
  if current_page.include? each_string
    %li 
    %a{ :href => "page#{page_options[:current_index]}-nf.html", :class => "next" }
    # This is the last ancor
    break
  else
    %li 
    %a{ :href => "page#{page_options[:current_index]}.html", :class => "next" }
    # This is the last ancor
    break
  end
end

다른 팁

좋아, 그래서 우리는 page_options [: current_index] 중 어느 것도 current_page의 하위 문자인지 확인하고 있다고 생각합니다.

if page_options[:current_index] < page_options[:total_index] && page_options[:current_index] > 0

found_item = false

// loop through the pre-flash array and if current page matches, add -nf
- page_options[:pre_flash] = ['string_one-nf', 'string_two-nf', 'string_three-nf']
- page_options[:pre_flash].each do |each_string|

    - if current_page.include? each_string
            found_item = true
            %li 
                    %a{ :href => "page#{page_options[:current_index]}-nf.html", :class => "next" }
                            Next

# do whatever you need to get out of the staticmatic block...

    - if !found_item

            %li
                    %a{ :href => "page#{page_options[:current_index]}.html", :class => "next" }

죄송합니다 - 당신이하고있는 일을 오해했습니다 ... 당신이 포함하고 있다고 생각 했습니까? 배열에서는 끈이었다 ... :-)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top