首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Rails 4强参数ActiveModel::ForbiddenAttributesError

Rails 4强参数ActiveModel::ForbiddenAttributesError
EN

Stack Overflow用户
提问于 2013-10-18 18:38:19
回答 1查看 851关注 0票数 1

由于某些原因,在我当前的控制器中,我得到了ActiveModel::ForbiddenAttributesError,尽管我相信我使用的是很强的参数。尽管我正在使用许可证!暂时允许所有模型属性。参见下面的代码,我遗漏了什么?

代码语言:javascript
复制
class HeuristicsController < ApplicationController

    def index
        @heuristics         = Heuristic.order(:name).page params[:page]
        @heuristic      = Heuristic.new
    end

    def create
        @heuristic = Heuristic.new(params[:heuristic])
        if @heuristic.save
            redirect_to action: 'index', :flash => {:success => "New heuristic created!" }
        else
            render 'new'
        end
    end

    def new
        @title              = "Heuristic"
        @heuristic          = Heuristic.new
    end

    private

    def heuristic_params
        params.require(:heuristic).permit!      
    end

end
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-10-18 18:55:23

我想你还没完全理解强对撞机的工作方式.

你有个方法

代码语言:javascript
复制
def heuristic_params
    params.require(:heuristic).permit!      
end

而且你没有使用它

代码语言:javascript
复制
Heuristic.new(params[:heuristic])
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19456809

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档