ActiveModel::ForbiddenAttributesError when creating new user

后端 未结 7 1823
礼貌的吻别
礼貌的吻别 2020-11-22 15:59

I have this model in Ruby but it throws a ActiveModel::ForbiddenAttributesError

class User < ActiveRecord::Base
  attr_accessor :password
  v         


        
7条回答
  •  抹茶落季
    2020-11-22 16:52

    For those using CanCan. People might be experiencing this if they use CanCan with Rails 4+. Try AntonTrapps's rather clean workaround solution here until CanCan gets updated:

    In the ApplicationController:

    before_filter do
      resource = controller_name.singularize.to_sym
      method = "#{resource}_params"
      params[resource] &&= send(method) if respond_to?(method, true)
    end
    

    and in the resource controller (for example NoteController):

    private
    def note_params
      params.require(:note).permit(:what, :ever)
    end
    

    Update:

    Here's a continuation project for CanCan called CanCanCan, which looks promising:

    CanCanCan

提交回复
热议问题