How best to DRY will_paginate options

后端 未结 2 1754
误落风尘
误落风尘 2021-02-15 05:34

I have 8 controllers using will_paginate to paginate their index pages. I\'d like to override the defaults for \"Previous\" and \"Next\" on each without having to specify the s

2条回答
  •  -上瘾入骨i
    2021-02-15 06:11

    will_paginate uses I18n so you can just use that. Given you use English as the default locale the following line should be present in application.rb:

    config.i18n.default_locale = :en
    

    you can then change the text of the pagination links by adding the following to config/locales/will_paginate.en.yml:

    en:
      will_paginate:
        previous_label: "← go back"
        next_label: "go forward →"
    

    Alternatively you can add them to your default translations file: config/locales/en.yml but I have found that it quickly becomes to large to handle.

    Note: If you use another locale, for instance es, for this to work you need to at least replace the en: keys within the YAML files to es: and to be concise about naming your files, use either config/locales/will_paginate.es.yml or config/locales/es.yml.

提交回复
热议问题