ActiveModel::ForbiddenAttributesError - strong parameters

后端 未结 1 1245
慢半拍i
慢半拍i 2021-01-28 14:02

So I am following one tutorial that is obviously done in rails 3 and I am using rails 4. I get this error:

ActiveModel::ForbiddenAttributesError

相关标签:
1条回答
  • 2021-01-28 15:02

    You need to make sure that all attributes required to create a Movie are whitelisted.

    Define a method like this in your controller:

    private
    def movie_params
      params.require(:movie).permit(:title, :rating, :release_date)
    end
    

    And then pass the result of the method into create!:

    def create
      @movie = Movie.create!(movie_params)
      # ...
    end
    

    Read more about strong parameters in the Rails documentation.

    0 讨论(0)
提交回复
热议问题