1

我有以下内容:

class PhotoLibrariesController < ApplicationController

  def create
    @photo_library = PhotoLibrary.new(photo_library_params)

    if @photo_library.save
      respond_to do |format|
        format.html { redirect_to photo_libraries_path }
        format.js
      end
    else
      flash[:alert] = 'Photo Library not created successfully'
      render :new
    end
  end

  def new
    @photo_library = PhotoLibrary.new
  end

  def index
    @photo_libraries = PhotoLibrary.all
  end

  private

  def photo_library_params
    params.require(:photo_library).permit( :title )
  end
end

这总是导致:

WARNING: Can't mass-assign protected attributes for PhotoLibrary: title
    app/controllers/photo_libraries_controller.rb:35:in `create'

我在这里做错了什么?为什么 strong_parameters 似乎不起作用?

4

1 回答 1

3

我认为您需要删除或设置为 false 中的以下配置config/application.rb

config.active_record.whitelist_attributes = false
于 2013-06-25T18:20:49.737 回答