ruby on rails - Permit same parameter for array and string -


my user input has location key, value can array:

params # => {"location"=>["california", "new york"], "email"=>"test@test.com", "name"=>"test"} 

or string:

params # => {"location"=>"california", "email"=>"test@test.com", "name"=>"test"} 

i'm wondering best way permit array or string.

the cleanest way can see add both :location , location: [] permitted parameters, i'm not sure if proper way accomplish this.

def params   params.permit(     :name,     :email,     :location,     location: []   ) end 

any advice? correct way this?

remember, permit used whitelist parameters active model mass assignment. solution might fine. way force location array (if it's array unchanged):

def permitted_params   params["location"] = array(params["location"])   params.permit(     :name,     :email,     location: []   ) end 

Comments