All threads / Raisl 4 : Exception Site(#70058148983820) expected, got String(#8388700)

Ask A Question


You’re not receiving notifications from this thread.

Raisl 4 : Exception Site(#70058148983820) expected, got String(#8388700)

Laurent Passebecq asked in Rails

I have a form with a selectbox which allow to select differents values. When I want to save the form I have an exception :

ActiveRecord::AssociationTypeMismatch at xxxxxxxxxxxxxxxxxxxxx
Site(#70058148983820) expected, got String(#8388700)

Here is the form which generate the select box

= f.collection_select :wishes_sites, @sites, :id, :name, {:selected =>}, {:multiple => true, :class=>"sites_multiselect"}

In my controller I have

    def user_params
        :wishes_sites =>[],

The model

    class User < ActiveRecord::Base
      has_and_belongs_to_many :wishes_sites, :class_name => "Site", :join_table => :wishes_sites

here is the line which produces the bug
if @user.update_attributes(user_params)

Here are the migration

    create_table :sites, force: true do |t|
      t.string   "name"
      t.datetime "created_at"
      t.datetime "updated_at"
      t.text     "address"
      t.text     "description"

    create_table :wishes_sites, id: false, force: true do |t|
      t.integer "user_id"
      t.integer "site_id"

Thanx for your help

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 53,130+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2021 GoRails, LLC. All rights reserved.