Help Updating Database With Checkboxes

I don’t understand your code very well, but i think that you need something like this:

http://wiki.rubyonrails.org/rails/pages/CheckboxHABTM

The answer about the negative id is on:

@orderitem = OrderItem.find(:all)

@lineitem.order_item_id = @orderitem.id

@orderitem is an Array!

Has many through gives more flexibility, no?

-Thufir

I think that what you need is just a checkbox like:

<%= check_box_tag “line_item[orderitem_ids][]”, orderitem.id %>

And so,

@lineitem = LineItem.new(params[:line_item])
@lineitem.save

will works fine!

P.S.: the problem about the negative Array id, is because the Array id is the Ruby object id, not an ActiveRecord id.

Thufir:

Has many through gives more flexibility, no?

Yes, in this case through is the best solution, but the problem about creation will be solved at the some way.

Mr. Bill:

Post your models’s source.

Your OrderItem model has not the belongs_to :line_items, but this is not the problem.
I can’t understand why method missing, because you have has_many :order_items…

Well, sory, but i can’t help more.

For a HABTM (Has and Belongs To Many) I believe that you need to
change the names for tables and classes. It seems contentious, but to
my understanding it would be:

class Order
class Item
class ItemOrder

corresponding to:

table orders
table items
table items_orders

or, perhaps it's item_orders, or order_items for the table name. That
part seems contentious. Oh, I find "item" to be kinda vague as it
could be any kind of item. How about "dish", "entree" or "food"?

-Thufir