简体   繁体   English

Rails不允许选择的参数

[英]Rails Unpermitted parameters for select

I am trying to add a record that contains a list of strings. 我正在尝试添加包含字符串列表的记录。

model: 模型:

class Startup < ActiveRecord::Base
  before_validation(:on => :create) do
    self.mal = false
  end
  serialize :category
  attr_accessible :name, :url, :description, :category, :creator, :mal, :founded
end

but I still get this error in my logs: 但是我的日志中仍然出现此错误:

Started POST "/startups" for 127.0.0.1 at 2013-04-25 05:05:00 -0300
Processing by StartupsController#create as JS
  Parameters: {"utf8"=>"✓", "startup"=>{"name"=>"test", "url"=>"http://startupcrawler.com", "category"=>["", "Analytics", "Fitness", "Gaming"], "founded(1i)"=>"2013", "founded(2i)"=>"4", "founded(3i)"=>"1", "description"=>"fdsa"}, "commit"=>"Create Startup"}
Unpermitted parameters: category
  [1m[35m (0.2ms)[0m  BEGIN
  [1m[36m (0.2ms)[0m  [1mROLLBACK[0m
Completed 500 Internal Server Error in 85ms

What am I doing wrong? 我究竟做错了什么? Why won't category serialize? 为什么类别不序列化?

EDIT: 编辑:

Just found out this method is deprecated and I'm using Rails 4... what should I use instead? 刚刚发现此方法已被弃用,而我正在使用Rails 4 ...我应该改用什么呢?

EDIT 2: 编辑2:

Now getting this in logs: 现在将其记录在日志中:

Started POST "/startups" for 127.0.0.1 at 2013-04-25 05:30:33 -0300
Processing by StartupsController#create as JS
  Parameters: {"utf8"=>"✓", "startup"=>{"name"=>"blah", "url"=>"http://startupcrawler.com", "category"=>["", "Fitness"], "founded(1i)"=>"2013", "founded(2i)"=>"4", "founded(3i)"=>"1", "description"=>"fdsa"}, "commit"=>"Create Startup"}
  [1m[36m (0.2ms)[0m  [1mBEGIN[0m
  [1m[35m (0.5ms)[0m  ROLLBACK
  Rendered startups/_form.html.erb (16.1ms)
  Rendered startups/new.html.erb within layouts/application (18.9ms)
Completed 200 OK in 128ms (Views: 29.9ms | ActiveRecord: 0.8ms)

but no new record is created (ROLLBACK for some reason). 但未创建新记录(出于某种原因回滚)。

I removed serialize :category from the model. 我从模型中删除了serialize :category This is in my controller now: 现在在我的控制器中:

def startup_params
      params.require(:startup).permit(:name, :url, :added, :founded, :mal, :creator, :description, {:category => []})
end

因此,Rails 4内置了强大的参数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM