Hi,
I have a view that displays a list of items from a database table called
“order_items”. Each item has a checkbox next to it. I need the user to
be able to select multiple items with the checkboxes and have those
items update another database table called “line_items”. Whenever I save
the form, in the “line_item_id” column of the “order_item_id” table I
keep seeing stuff like “-615326988”, which is obviously incorrect. What
is that weird negative number? Why does it put that instead of what I
need?
Below is what I’m working with so far…
Controller:
[CODE]
def create
@order = Order.new(params[:order])
@lineitem = LineItem.new(params[:line_item])
@orderitem = OrderItem.find(:all)
if @order.save
@lineitem.order_id = @order.id
@lineitem.order_item_id = @orderitem.id
if @lineitem.save
LineItem.update_all([“issued_date=?”, Time.now], :id =>
params[:orderitem_ids])
redirect_to :controller=> ‘orders’, :action => ‘viewAllOrders’
else
flash[:warning] = “Error - orders controller - @lineitem not
saved.”
end
else
flash[:warning] = “Error - orders controller - @order not saved.”
end
end[/CODE]
View:
<% form_tag({:action => 'create'}, {:id=> 'page1'}) do %>
<% @orderitem.each do |orderitem| %>
<%= check_box_tag "orderitem_ids[]", orderitem.id %>
<%= orderitem.name %>
<% end %>
<% end %>
Output:
Processing OrdersController#create (for 127.0.0.1 at 2007-12-26
12:07:42) [POST]
Session ID: 57faab505a5f2807583b841df5d58534
Parameters: {“commit”=>“Create”, “order”=>{“location_id”=>“3”},
“action”=>“create”, “controller”=>“orders”, “orderitem_ids”=>[“1”, “3”],
“line_item”=>{“quantity_requested”=>“4”}}
SQL (0.000104) BEGIN
SQL (0.043289) INSERT INTO line_items (order_id
, order_item_id
,
quantity_requested
, issued_date
, price_at_order
, parlevel
,
quantity_issued
) VALUES(80, -615326988, 4, NULL, NULL, NULL, NULL)
SQL (0.001171) COMMIT
LineItem Update (0.000302) UPDATE line_items SET
issued_date=‘2007-12-26 12:07:42’ WHERE (line_items.id
IN (‘1’,‘3’))
Generated Page Source:
Item X