I'm trying to convert a string to an array. The method I'm using seems to be working but when I check with pry it's still a string. Let me show you my method and output and see if you can tell me what's wrong. Thank you.
Method:
def filters=(filters)
if filters.is_a?(String)
filters = filters.split(",")
end
list = Set.new
Array.wrap(filters).each do |filter|
filter.tr!(",", " ")
filter.strip!
list << filter unless filter == ""
end
super(list.to_a)
end
View
in the text field I placed hey, ohh
<%= form_for @integrations, url: url_for(:controller => :integrations, :action => :update, :id => @integrations.id) do |f| %>
<%= f.label :filters %>
<%= f.text_field :filters, class: "filter-autocomplete" %>
<%= f.submit "Save" %>
<% end %>
Controller
def update
@integrations = current_account.integrations.find(params[:id])
if @integrations.update_attributes(update_params)
flash[:success] = "Filters added"
redirect_to account_integrations_path
else
render :filters
end
end
def filters
@integrations = current_account.integrations.find(params[:id])
end
if you put a pry on the end of that it seems that it has converted to an array. but when I check the object it still remains a string.
when I look at my filters now in the console they look like this
"[\"Hey\", \"ohh\"]"
when I want it to look like:
["Hey", "ohh"]