Search code examples
ruby-on-railsrubyactivescaffold

Is there anyway to make activescaffold work with accepts_nested_attributes_for?


I have a child model which accepts_nested_attributes_for another model in a has_one / belongs_to relationship. I am trying to configure the activescaffold controller like this:

config.create.columns = [:name, :birthdate, :device_attributes]

But it just throws this error:

undefined method `device_attributes' for #<Child:0xc103e28>

Note: I have overridden the default create_form with a custom implementation.


Solution

  • I found a way to make it works. I just added this to the activescaffold controller:

      def before_create_save(record)
        record.device_attributes = params[:record][:device_attributes]
      end
    
      def before_update_save(record)
        record.device_attributes = params[:record][:device_attributes]
      end
    

    It's not the cleaner way to do it, but i didn't find other way.