Recourse

Customizing

Anything the gem draws, the host can write itself, and a file the host has is left alone.

A row of your own

<%# app/views/posts/_row.html.erb %>
<%# locals: (post:) -%>

<%= column header: sort_header(:title) do %>
  <%= search_highlight post.title, :title %>
<% end %>

<%= column header: 'Author' do %>
  <%= post.author.name %>
<% end %>

One column per cell. sort_header draws a heading that sorts where it can, and search_highlight marks what the search matched. The partial is rendered once for the header row with the record nil, so nothing outside a column block may read it. The action columns and the bookmark square are still drawn ahead of it. A link in a cell uses turbo_link_to, never link_to.

The fields of a form

A _fields.html.erb under the resource replaces the fields and keeps the form, the submit and the errors, on both new and edit.

A template of your own

A show, edit or nested index template replaces the body of the page and nothing else: the card, its tabs, the buttons beside the breadcrumb and the title stay the layout’s. The record arrives as @post, and the parent of a nested page as @recourse_parent. @recourse_card = false takes the card away; content_for :title still wins.

A controller of your own

A host controller is a RecoursesController, and one private method usually does the job. The search, the sort, the filters, the pages and the cache still come from the gem.

class Projects::CommentsController < RecoursesController
private

  # The rows behind a table the gem draws whole.
  def recourse_relation
    project = Project.find params.expect(:project_id)
    Comment.where task: project.tasks
  end
end

recourse_model names the model behind a page named for something else: def recourse_model = Order under recourses :purchases. find_resource finds a singular record the parent names no association for: assign @recourse_parent.team.manager. create, update and destroy are ordinary actions a host with something of its own to do rewrites; what the gem does inside them is private.