ruby - Rails 4 + Postgresql array type: Weird behavior when saving record, can't cast array -


so, i'm having following setup in rails 4 postgresql

# migration create_table :custom_category_groups |t|   t.string :name   t.string :content_types, array: true, default: [] end  # controller class customcategorycontroller < applicationcontroller   # ...   def update     @custom_category_group = customcategorygroup.new(custom_category_group_params)     if @custom_category_group.update(custom_category_group_params)       # ...     end   end  private   def custom_category_group_params     params.require(:custom_category_group).permit(:name, content_types: [])   end end  # view = form_for @custom_category_group |f|   = f.collection_check_boxes :content_types, %w(interviews testimonials blogs).map { |ct| [ ct.titleize, ct ] }, :last, :first 

when i'm saving custom category group following error:

typeerror - can't cast array 

when take in log see following db statement being issued:

update "custom_category_groups" set "content_types" = $1, "updated_at" = $2  "custom_category_groups"."id" = 2  [[nil, ["interviews", ""]],  ["updated_at", mon, 26 aug 2013 12:15:53 utc +00:00]] 

as can see rails somehow can't resolve proper name content_types (the nil in braces after where clause).

the weird thing: if reload page , submit form again (when browser asks) me, saving works!????


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -