1

ここにアンカーを1つだけ出力したい。current_pageが配列内にある場合、2つ(.htmlと-nf.html)を取得します。配列にない場合は、配列にあるアイテムと同じ数のアンカーを取得します。

StaticMaticを使用しています。

- 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
4

2 に答える 2

2
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
于 2009-12-01T00:35:17.380 に答える
1

さて、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" }

すみません-私はあなたがしていることを誤解しました...あなたがインクルードをしていると思いましたか?配列上ですが、文字列でした... :-)

于 2009-12-01T00:36:04.897 に答える