在rails 5中使用smart_listing gem时出现ActionController :: UnfilteredParameters错误

时间:2017-12-28 18:41:15

标签: ruby-on-rails ruby smart-listing

我不知道在我的rails应用程序中导致此问题的原因。我正在尝试在我的sprint模型上应用smart_listing gem表排序功能。

enter image description here

冲刺控制器:

def index
  @sprints = smart_listing_create :sprints, Sprint.all, partial: "sprints/listing", default_sort: { number: "asc" }
  @sprint = Sprint.new
end
...
def permitted_params
  params.require(:sprint).permit(:number, :start_date, :end_date)
end

index.html.slim:

= smart_listing_render(:sprints)

_listing.html.slim:

- unless smart_listing.empty?
  table.ui.celled.table
    thead
      th.header = smart_listing.sortable "Number", :number
      th.header = smart_listing.sortable "Start Date", :start_date
      th.header = smart_listing.sortable "End Date", :end_date
    tbody
      - smart_listing.collection.each do |sprint|
        tr
          td.header
            = sprint.number
          td.description
            = "#{sprint.start_date.strftime("%d-%m-%Y")}"
          td.description
            = "#{sprint.end_date.strftime("%d-%m-%Y")}"

    = smart_listing.paginate
 - else
   p.warning No records!

我知道这将是一个非常小的错误,但我无法在24小时内解决这个问题:/并且无法在stackoverflow /任何其他博客上找到任何其他类似的问题。

谢谢你:)

1 个答案:

答案 0 :(得分:1)

目前看起来似乎是GitHub issue

  

以下pull会更改to_h的行为以取消允许   参数 -

     

rails/rails#28734

     

使用。进行排序时,此更改会导致数组集合失败   错误"无法将未经许可的参数转换为哈希"。

人们解决此问题的一种方法是执行以下操作:

  

self.params = params.permit!之前在控制器中执行smart_listing_create似乎也可以解决问题。

我在这里添加一个免责声明。 params.permit!将允许所有当前和未来的参数。使用它时应该非常小心。 Read the official documentation了解更多信息。