I have this in my template:
<%= f.hidden_field :user_ids, multiple: true, value: 1 %>
<%= f.hidden_field :user_ids, multiple: true, value: 2 %>
On the controllerI have this to make sure that the array is an array of integers. I tested it and it works fine :
before_filter :parse_json_request
def parse_json_request
params[:keepcon_settings_users_group][:user_ids] = params[:keepcon_settings_users_group][:user_ids].map(&:to_i) if params[:keepcon_settings_users_group][:user_ids]
end
The problem is that the data is storing as a yaml but in this format:
---
- '1'
- '2'
And I need it this way:
---
- 1
- 2
My class is:
class UsersGroup < ActiveRecord::Base
belongs_to :account_setting
serialize :user_ids, Array
attr_accessible :name, :user_ids
after_initialize :set_defaults
def set_defaults
if !self.user_ids or self.user_ids == ''
self.user_ids = []
end
end
end