我正在使用Rails引擎(社交流),它在rails 3应用程序中使用了strong_parameters gem。当尝试更新时,我会收到错误,但无法确定问题所在。ActiveModel :: ForbiddenAttributes与Rails引擎
我在更新操作上使用模态ajax表单,并使用update_attributes。我已经添加了更新,以私人allowed_params方法的属性,但我得到一个 ::加载ActiveModel ForbiddenAttributes(::加载ActiveModel ForbiddenAttributes):错误
ActiveModel::ForbiddenAttributes (ActiveModel::ForbiddenAttributes):
<a href="txmt://open? url=file:///Users/sean/Dropbox/fluent/fluent100/app/controllers/sentences_controller.rb&line=18&column=1">app/controllers/sentences_controller.rb:18:in `update'</a>
使用强大的参数文件(https://github.com/rails/strong_parameters#readme),我试图确定问题属性可能是什么,但rails日志不提供任何信息。
我尝试设置config.action_controller.action_on_unpermitted_parameters =:登录在development.rb但我的应用程序将不会启动:
undefined method `action_on_unpermitted_parameters=' for ActionController::Base:Class (NoMethodError)
从我的控制器:
def update
@sentence.update_attributes params[:sentence]
if @sentence.valid?
flash[:notice] = 'Sentence was successfully updated.'
end
.
.
private
def allowed_params
[:id, :title, :text, :description, :difficulty, :sentence]
end
的allowed_params方法在gem代码中被引用,并且似乎将允许的参数传递给strong_paramaters gem。
protected
def whitelisted_params
return {} if request.present? and request.get?
params.require(self.class.model_class.to_s.underscore.to_sym).permit(*all_allowed_params)
end
def allowed_params
[] # This should be overriden in controllers to allow extra params
end
def all_allowed_params
COMMON_PARAMS |
activity_object_property_params |
allowed_params
end
其他注意事项:
* UPDATE * 更新似乎当我使用的工作:的
update!
代替
@sentence.update_attributes params[:sentence]
我不清楚为什么。