【问题标题】:Rails 6 Filterrific Syntax Error in _list.html.erb_list.html.erb 中的 Rails 6 Filterrific 语法错误
【发布时间】:2020-02-05 11:28:21
【问题描述】:

我将尽可能密切关注,以使用http://filterrific.clearcove.ca/pages/action_view_api.html 为例在玩家模型上设置简单过滤。但是,我不断收到下面的语法错误,显然我在这里遗漏了一些东西!

错误

syntax error, unexpected '<', expecting ')'
  </div>
  ^
/home/jack/Itorix/app/views/players/_list.html.erb:10: unknown regexp options - th

玩家控制器

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

玩家模型

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 %>

【问题讨论】:

  • 你能提供声明filterrific_sorting_link的代码吗?
  • 它是过滤宝石的一部分
  • 你是否在使用 Rails 6 时得到了过滤?
  • @hashrocket,不在 rails 6 中,没有,在 5 中重新开始,没有任何问题
  • 我很想知道人们是如何在 Rails 6 中实现这一点的!

标签: javascript ruby-on-rails filterrific


【解决方案1】:

刚刚遇到这个问题并通过删除 _list 文件中的内联 cmets 解决了它。从page_entries_infowill_paginate 中删除# provided by will_paginate,语法错误就会消失。

【讨论】:

    猜你喜欢
    • 2014-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多