Ask A Question

Notifications

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

col-md-9
.input-group.btn-group
%span.input-group-addon
=t('activerecord.attributes.user.volunteer_wishes_sites')
= f.collection_select :wishes_sites, @sites, :id, :name, {:selected => @user.wishes_sites.map(&:id)}, {:multiple => true, :class=>"sites_multiselect"}

In my controller I have

    def user_params
      params.require(:user).permit(
        :wishes_sites =>[],
      )
    end

The model

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

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"
    end

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

Thanx for your help

Reply
Join the discussion
Create an account Log in

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

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

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