我想更改强参数中的属性名称,使其最后没有“_attributes”。
我有:
params.require(:setting).permit(:recording,
:special_settings_attributes => [:orientation])
我正在测试它:
describe "Settings Creation" do
context 'new setting success' do
before do
a = post :create, format: :json, :setting => {
:recording => "recorded",
:special_settings_attributes => [:orientation => "left"]
}
end
it 'creates a new setting' do
expect(Setting.last.special_settings.last.orientation).to eq("left")
end
end
end
end
我要
params.require(:setting).permit(:recording,
:special_settings => [:orientation])
我当然尝试过重命名,但是没有创建 SpecialSetting 模型..
最佳答案
只需在您的任何操作调用/使用它之前更改您的params
:
before_action do
params[:special_settings_attributes] ||= params.delete :special_settings
end
关于ruby-on-rails - 具有自定义嵌套属性名称的 Rails 4 强参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30516541/