2013-05-27 40 views
0

我正在使用Rails引擎(社交流),它在rails 3应用程序中使用了strong_parameters gem。当尝试更新时,我会收到错误,但无法确定问题所在。ActiveModel :: ForbiddenAttributes与Rails引擎

我在更新操作上使用模态ajax表单,并使用update_attributes。我已经添加了更新,以私人allowed_pa​​rams方法的属性,但我得到一个 ::加载ActiveModel ForbiddenAttributes(::加载ActiveModel ForbiddenAttributes):错误

ActiveModel::ForbiddenAttributes (ActiveModel::ForbiddenAttributes): 
    <a href="txmt://open? url=file:///Users/sean/Dropbox/fluent/fluent100/app/controllers/sentences_controller.rb&amp;line=18&amp;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_pa​​rameters =:登录在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_pa​​rams方法在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 

其他注意事项:

https://groups.google.com/forum/?fromgroups#!searchin/social-stream/whitelist/social-stream/_aManxsvGHI/_XNHZVwB1C4J

* UPDATE * 更新似乎当我使用的工作:的

update! 

代替

@sentence.update_attributes params[:sentence] 

我不清楚为什么。

回答

0

更新!方法的作品,我选择了去。

def update 
    update! do |success, failure| 
    failure.html { render 'edit_modal', layout: false } 
    success.html { 
     load_sentences 
     render partial: 'table', locals: { sentences: @sentences } 
    } 
    end 
end