Ruby on Rails Wednesday, June 25, 2014



On Wednesday, June 25, 2014 8:26:37 AM UTC-4, Frederick Cheung wrote:
On Wednesday, June 25, 2014 10:31:01 AM UTC+1, Chris Butcher wrote:
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


If the  input name (as in the name attribute on the input element ends in [] then rails will treat the parameter as an array. I assume simple_form has a way for you to override the input name generated, but I've not used it so I don't know.

Fred


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

I'm working on this as I would like to have a more permanent solution for using the new fields in PostgreSQL.  Fred is correct, I'm getting the following message:

Unpermitted parameters:  impact, likelihood

The bigger issue is that these fields are being presented in html as number fields, meaning the user can only see or enter one number.  I'm not sure exactly how you would want to present your arrays, how big they will be, and how the user will enter values or update them.  The only time I've used this functionality is for tags and I limit it to ten tags. 

I got around many of the issues by creating a textarea field and allowing the user to enter tags separated by spaces.  I then converted the textarea to an array in the controller before passing it to the model object.  

I'm don't think that's a great architecture, and it violates the DRY principle because I do that in both the create and update methods.  I'll let you know if I come up with some better answers. 

Also, FYI, activerecord, for some reason cannot detect changes made to array columns.  Therefore, you have to force the issue by calling something like the following:

@risk.impact_will_update!

before saving the record or updating attributes.

--
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/9261e0b6-8bd3-4529-b454-e72f3e57c34a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment