0
在控制器我有以下:在軌道4的控制器,thing_params.delete(:東西)不刪除:東西鍵值對
# app/controllers/things_controller.rb
def create
kind = thing_params.delete(:kind)
detail_attributes = thing_params.delete(:detail_attributes)
@detail = Detail.create(kind, detail_attributes)
@thing = current_user.things.build(thing_params)
...
end
private
def thing_params
params.require(:thing).permit(
:name,
:position,
:kind,
{ detail_attributes: [ :detail_category_id, ... ] },
end
兩個kind
和detail_attributes
在被正確地設置create
方法的前兩行。但是,thing_params.delete(:kind)
不會從thing_params
散列中刪除「kind」鍵值對。與:detail_attributes
一樣。
我該怎麼做才能將它們從thing_params
中刪除?
當然!謝謝。 – robertwbradford