2

I have a model which has an array of strings.

class A < ApplicationRecord
  serialize :vals, Array
end

How can I get my controller

class AController < ApplicationController
  def create
    par = params.require(:a).permit(:vals)
    ...
  end
end

to accept an array of inputs?

0

1 Answer 1

2

Try declaring it as an array of values:

def create
  par = params.require(:a).permit(vals: [])
  ...
end
Sign up to request clarification or add additional context in comments.

4 Comments

rails does not like this if I have more than one parameter e.g. params.require(:a).permit(:b,vals:[])
How's it? Rails doesn't like it?
Apparently, this only happens if you put vals:[] in the middle of two parameters.
Yes, you're right, it must be added as the last value, not the first one, nor in the middle, although can be if it's the only one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.