我有这个控制器:
class AccountsController < ApplicationController
def create
if @current_account.update_attributes(account_params)
redirect_to :dashboard
end
end
def account_params
params.require(:account).permit(:company, users_attributes: [:name, phone_attributes: [:number]])
end
end
如您所见,我有 2 级嵌套属性,问题是我在使用强参数之前添加了一个虚拟属性,如下所示:
def create
@phone = @current_account.users.phone.requires_us_format = true
...
end
如何同时使用嵌套属性和强参数来实现这一点?