简体   繁体   中英

Render more-like-this view from button

I want to create a button from the search result from Solr (7.5.0) in Blacklight (7.0.1) which on click should render a more-like-this view.

I have tried to include the button in the catalog_controller and calling the more-like-this view through a helper function. Also tried to direct the routes in the routes.rb.

The catalog_controller:

config.add_index_field 'id', helper_method: :more_like_this

The helper function

def more_like_this
render_document_sidebar_partial
end

catalog_helper_behavior.rb

def render_document_sidebar_partial(_document = @document)
  render partial: 'show_sidebar'
end

Gives me the following error:

No route matches {:action=>"show", :controller=>"bookmarks", :id=>nil}, missing required keys: [:id]

How do I pass the id correctly?

I simply want Blacklight to render the more-like-this view in the right sidebar when the button is pushed.

Thanks in advance.

Two things are problems in what you've posted: 1. the show_sidebar partial expects to have a local called document, so should be called with something like:

 render partial: "show_sidebar", locals: { document: _document }
  1. the helper_method configuration for Blacklight fields identifies a method that expects to be called with an argument hash that minimally has a :document key for the SolrDocument and a :field key for the field name - the more_like_this method is a Rails helper (that is, it returns an html_safe string), not a Blacklight field value helper.

maybe you are missing the index action for bookmarks (in your routes and maybe in your controller).

the url you are going to is probably /bookmarks but you only have something like get "/bookmarks/:id" in your routes so it's not finding the required :id parameter.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM