1
我試圖添加一個包含字符串列表的記錄。Rails未選擇的參數
型號:
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
但我仍然得到這個錯誤在我的日誌:
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
我在做什麼錯?爲什麼不能類別序列化?
編輯:
剛剛發現這個方法已經過時,我使用Rails 4 ...我應該怎麼用呢?
編輯2:
現在,在日誌中獲得此:
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)
,但沒有新的記錄被創建(ROLLBACK出於某種原因)。
我從模型中刪除了serialize :category
。這是在我的控制器現在:
def startup_params
params.require(:startup).permit(:name, :url, :added, :founded, :mal, :creator, :description, {:category => []})
end
我會這樣做嗎? 'params.permit(:name,:url,:description,:category => [],:creator,:mal,:found)''而不是'attr_accessible'?我只包括'gem'attr_accessible'來滿足Devise的使用它仍然 – 2013-04-25 08:26:18
Devise有一個rails4分支,我認爲它與尚未發佈的Rails 4兼容。 – sevenseacat 2013-04-25 08:28:33
很酷,我可能會檢查一下。我現在得到了200個回覆,但是我的記錄沒有完成我已經在上面添加了編輯。 – 2013-04-25 08:38:00