我拼命尝试将一组默认值合并到我的嵌套参数中。不幸的是, usingdeep_merge
在 Rails 5 中不再起作用,因为它不再继承自Hash
.
所以这不起作用:
class CompaniesController < ApplicationController
def create
@company = current_account.companies.build(company_params)
if @company.save
flash[:success] = "Company created."
redirect_to companies_path
else
render :new
end
end
private
def company_params
params.require(:company).permit(
:name,
:email,
:people_attributes => [
:first_name,
:last_name
]
).deep_merge(
:creator_id => current_user.id,
:people_attributes => [
:creator_id => current_user.id
]
)
end
end
它给了我这个错误:
ActionController::Parameters:0x007fa24c39cfb0 的未定义方法“deep_merge”
那么怎么做呢?