ruby-on-railsmass-assignment

Is there an opposite function of slice function in Ruby?


In this post, slice function is used to get only necessary elements of params. What would be the function I should use to exclude an element of params (such as user_id)?

Article.new(params[:article].slice(:title, :body))

Thank you.


Solution

  • Use except:

    a = {"foo" => 0, "bar" => 42, "baz" => 1024 }
    a.except("foo")
    # returns => {"bar" => 42, "baz" => 1024}