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?
EDIT 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. This is in my controller now:
def startup_params
params.require(:startup).permit(:name, :url, :added, :founded, :mal, :creator, :description, {:category => []})
end
Strong parameters is built into Rails 4 for this reason.