0

これでいっぱいの設定ファイルがあります....

   - if current_page.include? "test_string_one"
      - @total_index = 3
      - @next_location = '../random_string/page0.html'
      - @next_name = 'title 2'

    - if current_page.include? "test_string_two"
      - @total_index = 10
      - @next_location = '../another_random_string/page0.html'
      - @next_name = 'title 3'

これを書くよりクリーンな方法はありますか?スタティックマティックの使用。

haml で利用できるフィルターがあるようです。これはすべて:rubyフィルターに入れる必要がありますか?

4

1 に答える 1

1

このコードはヘルパーに最適です。

次のようになります。

module SomeHelper

  def page_options
    @page_options ||= begin
      options = {}

      if current_page.include? "test_string_one"
         options[:total_index] = 3
         options[:next_location] = '../random_string/page0.html'
         options[:next_name] = 'title 2'
      elsif current_page.include? "test_string_two"
         options[:total_index] = 10
         options[:next_location] = '../another_random_string/page0.html'
         options[:next_name] = 'title 3'
      end

      options
    end

  end

end

次に、必要な各ページで、次のようなオプションにアクセスできます。page_options[:total_index]

于 2009-11-16T18:08:04.533 に答える