2

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

しかし、これまでのところ何も役に立ちませんでした。任意の提案をいただければ幸いです。ありがとう!

4

1 に答える 1