title_field
我不想定义一个单独的标题,而是根据文档的内容显示一个自定义标题。根据Blacklight Wiki,这可以通过设置config.index.document_presenter_class
自定义演示者来完成:
# app/controllers/catalog_controller.rb
class CatalogController < ApplicationController
...
configure_blacklight do |config|
...
config.index.document_presenter_class = MyPresenter
...
end
...
end
自定义演示者覆盖label
方法的地方:
# app/presenters/my_presenter.rb
class MyPresenter < Blacklight::IndexPresenter
def label(field_or_string_or_proc, opts = {})
# Assuming that :main_title and :sub_title are field names on the Solr document.
document.first(:main_title) + " - " + document.first(:sub_title)
end
end
当我这样做时,我的自定义标签方法似乎没有被调用,我通过添加一条puts
语句和一个调试器断点来检查它。
是否有我可能错过的内容或显示自定义文档标题的其他方式?