daveomcd
daveomcd

Reputation: 6555

How can I add to my params in Rails 5.1.4?

I have the following code that I use for sorting my table on my website. It was working in Rails 4.2, but after upgrading to Rails 5.1.4 it fails. As it should from what I've read in the changes for Rails 5. Though I understand due to the changes it's breaking I still don't understand how to tweak this method to get it working again, and would greatly appreciate it if someone could show me and explain. Thanks!

def roster_sort_link(column, title = nil)
  title ||= column.titleize
  direction = column == sort_column && sort_direction == "asc" ? "desc" : "asc"
  icon = sort_direction == "asc" ? "glyphicon glyphicon-chevron-up" : "glyphicon glyphicon-chevron-down"
  icon = column == sort_column ? icon : ""
  link_to "#{title} <span style='font-size: 10px;' class='#{icon}'></span>".html_safe, params.merge({column: column, direction: direction})
end

The issue comes in the last line of the method where it states:

params.merge({column: column, direction: direction})

The error I'm getting is the following:

unable to convert unpermitted parameters to hash

Upvotes: 0

Views: 678

Answers (1)

daveomcd
daveomcd

Reputation: 6555

Based on information I was given by @anothermh, I ended up doing this which seems to have worked.

From:

params.merge({column: column, direction: direction})

To:

params.permit(:column, :direction).merge({column: column, direction: direction})

Upvotes: 6

Related Questions