Ruby on Rails Sunday, June 29, 2014

've just started working on this again after some time off.

In response to Fred's suggestion regarding input names, I looked into it and found you can specify custom input names in simple form like this:

   <span class="impact-input">
   <%= f.input :impact, required: false, :error => false, input_html: { class: 'form-control', :name => "impact[]" } %>
   </span>
   <span class="likelihood-input">
   <%= f.input :likelihood, required: false, :error => false, input_html: { class: 'form-control', :name => "likelihood[]" } %>
   </span>

Note the ":name => " addition in the input_html attribute.

Now this has not fixed the problem at all with regards to app behaviour. However the error message ("unpermitted parameters...")  in terminal has disappeared when I attempt to submit a risk:


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:


   <span class="impact-input">

   <%= f.input :impact, as: :integer, required: false, :error => false, input_html: { class: 'form-control', :name => "impact[]" } %>

   </span>

   <span class="likelihood-input">

   <%= f.input :likelihood, as: :integer, required: false, :error => false, input_html: { class: 'form-control', :name => "likelihood[]" } %>

   </span>

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.

--
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/b22d6d2d-4362-41b9-90f7-6e33faf17804%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment