Forum: Ruby on Rails HABTM and Check Boxes (Yet Another thread on this)....

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
D38ed82faa0b3296a56c0f768f32ce57?d=identicon&s=25 Enzo Rivello (enzor)
on 2009-01-15 19:10
Hi there,

it's an afternoon that i'm destroying my head on this, and i've decided
to ask to you all .

I've got to do some check box lists for a modified substruct version i'm
doing, right now, i'm interested to insert a list of categories of
interests into a customer sheet

i'm using the substruct plugin version, wich stays in the plugin/vendor
the category.rb stays in the myapp/app/models , while the order_user.rb
stays in myapp/vendor/plugins/substruct/app/models .

this is my models

class Category < ActiveRecord::Base
  has_and_belongs_to_many :order_users

class OrderUser < ActiveRecord::Base
  include CheckboxSelectable
  has_and_belongs_to_many :categories
  #many other things down below

this are my controller

  def updateCust
       @customer = OrderUser.find(params[:id])
       @customer.update_check_list(params, 'Category')

        flash[:notice] = 'Customer was successfully updated.'
        redirect_to :action => 'customers'
            flash[:notice] = 'Something went wrong,please review your
            redirect_to :action => 'customers'

and the view

 <%= checkbox_select('customer', 'categories', @categories, 'name') %>

As you can see, i'm using the Checkbox select rails plugin (
I've already tried the version in the railscast
( but in both cases, the first time i
try to load the page, i get this error:

substruct_development.categories_order_users' doesn't exist: SELECT
`categories`.id FROM `categories`  INNER JOIN `categories_order_users`
ON `categories`.id = `categories_order_users`.category_id

, so i reload and all goes fine!ad the boxes too, they appears!

but if i try to check a box and then to save a record, i get this error:

ActiveRecord::AssociationTypeMismatch in

Category(#18224400) expected, got Category(#18557480)

or something similar, only numbers change!

Now, AssociationTypeMismatch is when you want to cope wrong types of
data together, but this is not the case :(

what i've to do? please help me!
D38ed82faa0b3296a56c0f768f32ce57?d=identicon&s=25 Enzo Rivello (enzor)
on 2009-01-16 10:12
no one can help me?
F028c9a42ccc0008521b475ecf25ea04?d=identicon&s=25 Bill Devaul (wdevaul)
on 2009-01-16 10:43
Enzo Rivello wrote:
> no one can help me?

What does your categories_order_users migration look like?
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-01-16 13:00
(Received via mailing list)
On 15 Jan 2009, at 18:10, Enzo Rivello wrote:

> or something similar, only numbers change!
> Now, AssociationTypeMismatch is when you want to cope wrong types of
> data together, but this is not the case :(
That sounds to me like an automatic code reloading problem: the plugin
isn't reloaded but your application's models are:
if the problem doesn't exist in production mode then that is the most
likely cause

D38ed82faa0b3296a56c0f768f32ce57?d=identicon&s=25 Enzo Rivello (enzor)
on 2009-01-17 21:05
problem fixed.

i just forgot to put the join table ._.

i feelin more noob than ever :P, but i learned something new! ;-)

Thanks everyone for the suggestions!
This topic is locked and can not be replied to.