Ruby on Rails Wednesday, June 25, 2014

Yes I think you are right. My logfile is unavailable for some reason ("postgres cannot access the server configuration file...") but I inspected my terminal after attempting a risk insert and this output looks exactly like what you are suggesting:

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!)


On Tuesday, June 24, 2014 9:56:45 AM UTC+1, Frederick Cheung wrote:
On Monday, June 23, 2014 10:12:04 PM UTC+1, Chris Butcher wrote:
   <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>

I don't know much about postgresql array columns and their interaction with simple_form but you should check whether the above form will result in params[risk][:impact] (and likelihood) being a string or an array.

If the params are strings it wouldn't surprise me if strong params rejected this since you told it to expect an array (is there anything from strong params in your logfile?)

Fred

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/4944c2b6-b4cf-4b91-8aa1-aea4459be934%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment