我有这个控制器:
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
如何使用嵌套属性和强参数实现此目的?