无法从ActiveAdmin接口更新资源 - ActiveModel :: ForbiddenAttributesError

时间:2013-12-02 07:30:11

标签: ruby-on-rails ruby activeadmin

当我尝试在Active Admin界面中更新资源的内容时,收到此错误:

ActiveModel::ForbiddenAttributesError in Admin::ThingsController#update
ActiveModel::ForbiddenAttributesError

Error Message

以下是ThingsController

中更新操作的内容
def update
    respond_to do |format|
      if @thing.update(thing_params)
        format.html { redirect_to @thing, notice: 'Thing was successfully updated.' }
        format.json { head :no_content }
      else
        format.html { render action: 'edit' }
        format.json { render json: @thing.errors, status: :unprocessable_entity }
      end
    end
  end

我必须添加到此块才能使其正常工作?我还注意到我无法在Active Admin界面中创建新资源。但是,我可以删除它们。

1 个答案:

答案 0 :(得分:3)

通过将此添加到admin / thing.rb

解决了这个问题
controller do
    def permitted_params
      params.permit thing: [ :title, :description, :image_file_name, :image_content_type, :image_file_size, ":image_updated_at(1i)", ":image_updated_at(2i)", ":image_updated_at(3i)", ":image_updated_at(4i)", ":image_updated_at(5i)"  ]
    end