Johshi Johshi - 1 year ago 108
Ruby Question

Strong params on a hash or array

In rails I did this in a model:

def update_user_ex(*attrs)
# .............

is an array with of a hash(es), for simplicity let's say it's a single hash.

How can I do this in Rails 4? "permit" doesn't work on a hash or array.

Answer Source

It's possible to use strong parameters outside of controllers per the documentation at


def update_user_ex(*attrs)
  params =
  user.assign_attributes(params.permit(:name, :email, :something_else)) 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download