2013-06-25 83 views
1

我有以下幾點:當我從Rails 3升級到Rails 4時,爲什麼strong_parameters不起作用?

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似乎不起作用?

+1

設置爲false以下配置你從photo_library刪除attr_accessible? –

+1

是的,它不在模型中...... – croceldon

回答

3

我認爲你需要刪除或config/application.rb

config.active_record.whitelist_attributes = false 
相關問題