John
John

Reputation: 634

Combine strong params with other params

How can I combine strong with other params when creating a new object.

def params_test
  params.permit(:test1, :test2, :test3)
end
a = Model.new(params_test)
a.test4 = 'test4'
a.test5 = 'test5'

Test4 and Test5 they are coming from DB or Cookies or other source in the system. Is there a way to combine all of them into one line? Or two lines?

Upvotes: 0

Views: 104

Answers (1)

apneadiving
apneadiving

Reputation: 115521

You could do:

Model.new(params_test.merge({ test4: 'test4', test5: 'test5'}))

Upvotes: 2

Related Questions