<span class="impact-input"><%= f.input :impact, required: false, :error => false, input_html: { class: 'form-control' } %></span><span class="likelihood-input"><%= f.input :likelihood, required: false, :error => false, input_html: { class: 'form-control' } %></span>
Started POST "/risks" for 127.0.0.1 at 2014-06-23 21:28:41 +0100
Processing by RisksController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"LOgpMvsEGkhQaoZX5BkrX+Nw1Ov9QQaHuQqWO+L8peI=", "risk"=>{"title"=>"afafafa", "description"=>"aadada", "area"=>"IT", "owner"=>"4", "action"=>"fffaa", "date_of_action(3i)"=>"23", "date_of_action(2i)"=>"6", "date_of_action(1i)"=>"2014", "action_completed"=>"0", "impact"=>"12", "likelihood"=>"11"}, "commit"=>"Create Risk"}
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."remember_token" = '1b3c0548b48b9f90cab54a695297436286ad0132' LIMIT 1
Unpermitted parameters: impact, likelihood
(0.1ms) BEGIN
SQL (0.3ms) INSERT INTO "risks" ("action", "area", "created_at", "date_of_action", "description", "owner", "title", "updated_at", "user_id") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) RETURNING "id" [["action", "fffaa"], ["area", "IT"], ["created_at", "2014-06-23 20:28:41.581267"], ["date_of_action", "2014-06-23"], ["description", "aadada"], ["owner", "4"], ["title", "afafafa"], ["updated_at", "2014-06-23 20:28:41.581267"], ["user_id", 2]]
(67.1ms) COMMIT
Redirected to http://localhost:3000/
Completed 302 Found in 73ms (ActiveRecord: 67.8ms)
So yeah - "Unpermitted parameters: impact, likelihood". Looks relevant. I have done some research into it, and it seems like one could serialise their inputs in the model using:
serialize :impact, Array
serialize :likelihood, Array
and I could change the array type in the schema to string. However, I would really rather keep the array as integers as it's going to make operations like averaging much easier without casting etc. Does anyone know of a way I can get these params accepted as integers? The problem might lie in simple form after all.
(Thanks for your help so far Frederick!)
So yeah - "Unpermitted parameters: impact, likelihood". Looks relevant. I have done some research into it, and it seems like one could serialise their inputs in the model using:
serialize :impact, Array
serialize :likelihood, Array
Started POST "/risks" for 127.0.0.1 at 2014-06-29 12:58:02 +0100
Processing by RisksController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"LOgpMvsEGkhQaoZX5BkrX+Nw1Ov9QQaHuQqWO+L8peI=", "risk"=>{"title"=>"aa", "description"=>"aadad", "area"=>"IT", "owner"=>"5", "action"=>"dadad", "date_of_action(3i)"=>"29", "date_of_action(2i)"=>"6", "date_of_action(1i)"=>"2014", "action_completed"=>"0"}, "impact"=>["4"], "likelihood"=>["4"], "commit"=>"Create Risk"}
User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."remember_token" = '1b3c0548b48b9f90cab54a695297436286ad0132' LIMIT 1
(0.2ms) BEGIN
SQL (0.3ms) INSERT INTO "risks" ("action", "area", "created_at", "date_of_action", "description", "owner", "title", "updated_at", "user_id") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) RETURNING "id" [["action", "dadad"], ["area", "IT"], ["created_at", "2014-06-29 11:58:02.816205"], ["date_of_action", "2014-06-29"], ["description", "aadad"], ["owner", "5"], ["title", "aa"], ["updated_at", "2014-06-29 11:58:02.816205"], ["user_id", 2]]
(0.3ms) COMMIT
Redirected to http://localhost:3000/
Completed 302 Found in 9ms (ActiveRecord: 1.2ms)
You can still see that the impact and likelihood fields are still omitted during the commit. Maybe this is because they are being passed in as strings (denoted by the quotes around the values you can see being passed in the terminal output above), even though the array is explicitly integer? I have tried forcing integers like this, but it has made no difference:
So I'm still stuck! If I change the input name like I have, would I have to adjust anything else in my application? This is my first rails project so forgive me if the answer to that is an obvious 'of course'.
Thank you both for your help thus far.
validates_inclusion_of :impact, :in => 0..100
I think you'll have to write a custom validation for this
validates :foo
def foo
# do whatever checks you want and call
# errors.add if the record isn't valid
end
I can never remember whether it is validate or validates.
Fred