我很难让 rails 4 与nested_attributes 一起工作并进行序列化。我有:
class Client < ActiveRecord::Base
belongs_to :event
serialize :phones
end
class Event < ActiveRecord::Base
has_one :client
end
class EventsController < ApplicationController
...
def event_params
params.permit(client_attributes: [:phones])
end
end
当我通过事件时:
{client_attributes: { phones: 'string'}}
它有效,但是当我尝试时
{client_attributes: { phones: [{phone_1_hash},{phone_2_hash}]}}
我收到“未经许可的参数:电话”消息并且字段未保存...
我试过用
class EventsController < ApplicationController
...
def event_params
params.permit(client_attributes: [phones:[]])
end
end
或者
class Client < ActiveRecord::Base
belongs_to :event
serialize :phones, Array
end
但到目前为止没有任何帮助。任何建议,将不胜感激。谢谢!