# HABTM and Check Boxes (Yet Another thread on this)

**URL:** <https://www.ruby-forum.com/t/habtm-and-check-boxes-yet-another-thread-on-this/157834>\
**Category:** Rails\
**Created:** [January 15, 2009, 7:10pm UTC](https://www.ruby-forum.com/t/habtm-and-check-boxes-yet-another-thread-on-this/157834 "2009-01-15T19:10:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![enzor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/bbe5ce/32.png) [@enzor](https://www.ruby-forum.com/u/enzor)\
**Post date:** [January 15, 2009, 7:10pm UTC](https://www.ruby-forum.com/t/habtm-and-check-boxes-yet-another-thread-on-this/157834/1 "2009-01-15T19:10:39Z")

</div>

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  
version.  
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  
end

class OrderUser \< ActiveRecord::Base  
include CheckboxSelectable  
has\_and\_belongs\_to\_many :categories  
#many other things down below  
end

this are my controller

def updateCust  
@customer = OrderUser.find(params[:id])  
@customer.update\_attributes(params[:customer])  
@customer.update\_check\_list(params, ‘Category’)

```
    if @customer.save
    flash[:notice] = 'Customer was successfully updated.'
    redirect_to :action => 'customers'
      else
        flash[:notice] = 'Something went wrong,please review your

```

data’  
redirect\_to :action =\> ‘customers’  
end  
end

and the view

\<%= checkbox\_select(‘customer’, ‘categories’, @categories, ‘name’) %\>

As you can see, i’m using the Checkbox select rails plugin (  
[http://scoop.cheerfactory.co.uk/2007/11/05/checkbox-select-rails-plugin/](http://scoop.cheerfactory.co.uk/2007/11/05/checkbox-select-rails-plugin/)  
).  
I’ve already tried the version in the railscast  
([#17 HABTM Checkboxes - RailsCasts](http://railscasts.com/episodes/17)) 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  
Admin/usersController#updateCust

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!

---

<div class="post-metadata">

**Author:** ![enzor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/bbe5ce/32.png) [@enzor](https://www.ruby-forum.com/u/enzor)\
**Post date:** [January 16, 2009, 10:12am UTC](https://www.ruby-forum.com/t/habtm-and-check-boxes-yet-another-thread-on-this/157834/2 "2009-01-16T10:12:53Z")

</div>

no one can help me?

---

<div class="post-metadata">

**Author:** ![enzor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/bbe5ce/32.png) [@enzor](https://www.ruby-forum.com/u/enzor)\
**Post date:** [January 16, 2009, 10:43am UTC](https://www.ruby-forum.com/t/habtm-and-check-boxes-yet-another-thread-on-this/157834/3 "2009-01-16T10:43:22Z")

</div>

Enzo R. wrote:

> no one can help me?

What does your categories\_order\_users migration look like?

---

<div class="post-metadata">

**Author:** ![enzor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/bbe5ce/32.png) [@enzor](https://www.ruby-forum.com/u/enzor)\
**Post date:** [January 16, 2009, 1:00pm UTC](https://www.ruby-forum.com/t/habtm-and-check-boxes-yet-another-thread-on-this/157834/4 "2009-01-16T13:00:18Z")

</div>

On 15 Jan 2009, at 18:10, Enzo R. 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

Fred

---

<div class="post-metadata">

**Author:** ![enzor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/bbe5ce/32.png) [@enzor](https://www.ruby-forum.com/u/enzor)\
**Post date:** [January 17, 2009, 9:05pm UTC](https://www.ruby-forum.com/t/habtm-and-check-boxes-yet-another-thread-on-this/157834/5 "2009-01-17T21:05:27Z")

</div>

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!
