我有一个包含嵌套属性的form_for的视图文件。最近,我添加了一个select标签来更新列:form_for对象的tile。出于某种原因,这个新列不会在提交时更新,但嵌套属性可以正常工作。
知道我在这里做错了什么吗?
<%= form_for @user, :html => {:class => "center"} , remote:true do |f| %>
#does not update the tile column in the user model. I want the tiles column to save a number between 1 to 10
<%= f.select(:tiles, [*1..10]) %>
#updates the nested attribute ontology.classification successfully
<%= f.fields_for :ontology do |ontology| %>
<%= ontology.select :classification,options_for_select(Tiles::ONTOLOGY_KEYS, selected:ontology.object.classification)%>
<%end%>
<%end%>
在用户模型中,我使用的是强参数
private
def user_params
params.require(:user).permit(:name, :tiles)
end
users表的架构如下:
create_table "users", force: true do |t|
t.string "name"
t.string "auth"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "tiles"
end
添加params哈希: 参数:
{"utf8"=>"✓", "user"=>{"tiles"=>"9", "ontology_attributes"=>{"classification"=>"P3", "id"=>"19"}, "things_attributes"=>{"0"=>{"uuid"=>"03F098C4-4FEB-4E44-B3AE-8B19B34E837D", "id"=>"58"}, "1"=>{"uuid"=>"92F3A722-4B54-4CF1-8EC9-465831D353B8", "id"=>"59"}, "2"=>{"uuid"=>"5BC5CFEF-3DD2-40B1-8113-2ABD5EA0570A", "id"=>"60"}}, "data_attributes_attributes"=>{"0"=>{"key"=>"$current_consumption", "id"=>"27"}, "1"=>{"key"=>"$power_consumption_deviation", "id"=>"28"}}}, "button"=>"", "id"=>"42"}
感谢您帮助我!