I'm following as closely as I can to set up simple filtering on a players model using http://filterrific.clearcove.ca/pages/action_view_api.html as an example. However, I keep getting the syntax error below, clearly I'm missing something here!
Error
syntax error, unexpected '<', expecting ')'
</div>
^
/home/jack/Itorix/app/views/players/_list.html.erb:10: unknown regexp options - th
Players Controller
def index
@filterrific = initialize_filterrific(
Player,
params[:filterrific]
) || return
@players = @filterrific.find.page(params[:page])
respond_to do |format|
format.html
format.js
end
end
Players Model
class Player < ApplicationRecord
filterrific(
default_filter_params: { sorted_by: 'tornid' },
available_filters: [
:sorted_by,
])
scope :sorted_by, ->(sort_option) {
# extract the sort direction from the param value.
direction = /desc$/.match?(sort_option) ? "desc" : "asc"
case sort_option.to_s
when /^tornid/
# Simple sort on the created_at column.
# Make sure to include the table name to avoid ambiguous column names.
# Joining on other tables is quite common in Filterrific, and almost
# every ActiveRecord table has a 'created_at' column.
order("players.tornid #{direction}")
else
raise(ArgumentError, "Invalid sort option: #{sort_option.inspect}")
end
}
end
Index.html.erb
<p id="notice"><%= notice %></p>
<h1>Players</h1>
<% js = escape_javascript(
render(partial: 'players/list', locals: { players: @players })
) %>
$("#filterrific_results").html("<%= js %>");
<%= form_for_filterrific @filterrific do |f| %>
<div>
Sorted by
<%= f.select(:sorted_by, @filterrific.select_options[:sorted_by]) %>
</div>
<div>
<%= link_to(
'Reset filters',
reset_filterrific_url,
) %>
</div>
<%# add an automated spinner to your form when the list is refreshed %>
<%= render_filterrific_spinner %>
<% end %>
<%= render(
partial: 'players/list',
locals: { players: @players }
) %>
<%= link_to "New Player", new_player_path %>
_list.html.erb
<%# app/views/players/_list.html.erb %>
<div id="filterrific_results">
<div>
<%= page_entries_info players # provided by will_paginate %>
</div>
<table>
<tr>
<th><%= filterrific_sorting_link(@filterrific, :tornid) %></th>
</tr>
<% players.each do |player| %>
<tr>
<td><%= player.tornid %></td>
</tr>
<% end %>
</table>
</div>
<%= will_paginate players # provided by will_paginate %>
Just came across this issue and solved it by removing the inline comments in the _list file. Remove the # provided by will_paginate
from both page_entries_info
and will_paginate
and the syntax errors go away.