I have the following Ruby on Rails params:
<ActionController::Parameters {"type"=>["abc, def"], "format"=>:json, "controller"=>"order", "action"=>"index"} permitted: false>
I want to check if there's a , in the string, then separate it into two strings like below and update type in params.
<ActionController::Parameters {"type"=>["abc", "def"], "format"=>:json, "controller"=>"order", "action"=>"index"} permitted: false>
I tried to do like below:
params[:type][0].split(",") #=> ["abc", " def"]
but I am not sure why there's a space before the second string.
How can I achieve that?
params[:type][0].split(",").compact.collect(&:strip)