首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >_list.html.erb中的Rails 6文件可怕的语法错误

_list.html.erb中的Rails 6文件可怕的语法错误
EN

Stack Overflow用户
提问于 2020-02-05 19:28:21
回答 1查看 210关注 0票数 0

我将以http://filterrific.clearcove.ca/pages/action_view_api.html为例,尽可能地在一个玩家模型上设置简单的过滤。然而,我一直收到下面的语法错误,显然我在这里遗漏了一些东西!

错误

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

播放器控制器

代码语言:javascript
复制
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

玩家模型

代码语言:javascript
复制
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

代码语言:javascript
复制
<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

代码语言:javascript
复制
<%# 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 %>
EN

回答 1

Stack Overflow用户

发布于 2020-12-15 19:17:55

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60074786

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档