强烈的参数问题在新的

时间:2014-01-30 23:53:40

标签: ruby-on-rails model ruby-on-rails-4 controller strong-parameters

当我在表单中按“创建”时,我有ActiveModel::ForbiddenAttributesError

在我的控制器中:

 def create
      @topic = Topic.new(topic_params)
      if @topic.save
         redirect_to topics_path, notice: 'Topic was successfully created.'
      else
         render action: 'new'
      end
 end
 def topic_params
      params.require(:topic).permit(:name, :published, :title)
 end

在视图中

    <%= f.input :title, label: 'Topic Name' , label_html: { class: "col-sm-4" } ,input_html: { class: 'col-sm-2 form-control' }, required: true %>

这是日志: 请求的参数是:

{"utf8"=>"✓", "authenticity_token"=>"uB3l+soqgt0qDX8JakSAPeBukp6oifViaHuxDxE9n/I=", "topic"=>{"title"=>"Selling2"}, "commit"=>"Update Page", "action"=>"create", "controller"=>"topics"}

当我编辑已经创建的主题时,我在尝试创建新主题时不会出现任何错误。

由于

1 个答案:

答案 0 :(得分:0)

感谢Logan

我的控制器filter_resource_access顶部有一个过滤器。我删除了,一切都很好。

无论如何,不​​确定为什么会出现filter_resource_access但这是另一个主题。

干杯谢谢洛根。

相关问题