Hello All, I am new to this Ajax update with form_remote_tag.
I have a model so a table with order_line_items which has a
order_line_item_status_code_id field.
I am listing the pending items just fine in a list view with a
dropdown select tag. I want to make update to Shipped with :onchange
from select field. Here is my code, it is not updating right now but
actually I don't know if anything is true here regarding the
form_remote_tag.
If the from only contains one field, then I suggest you forget about the
"form_remote_tag" and just use a simple select field with an onchange
attribute.
I made it work but without the id params which I need to find the
OrderLineItem. How can I pass the id param to the function. In view it
is sale_item.id. Should I use form_remote_tag again for this param
because I need to pass :id and :status_id both.
Also about rendering new objects, in my view, the table view would
rearrange after selection, I am listing shipped items on other table.
Is it possible? Or Should I figure out how to refresh the page?
I made it work but without the id params which I need to find the
OrderLineItem.
My bad, forgot to include that parameter.
<%= select_tag(:sale_item,
options_from_collection_for_select(@statuscodes, :id, :name), :onchange
=> remote_function(:update => 'repair_shop_selection', :url =>
{:controller =>'customer/orders', :action => 'change_sale_item_status',
:id => sale_item.id},
:with => "'brand_id=' + this.value") ) %>
Also about rendering new objects, in my view, the table view would
rearrange after selection, I am listing shipped items on other table.
Is it possible? Or Should I figure out how to refresh the page?
I dont know how much content is on the page, and how much of it has to
be updated. If most of it changes you can refresh it all, if not, just
replace the small bits that need updating and leave the rest alone.
Thanks so much for the help again : ) I solved it right now with
form_remote_tag, I was playing with it when I was waiting your answer.
Your code helped me alot to understand the process. Here is the code
working.
# If variations are present we get that as the ID instead...
sale_item = OrderLineItem.find(params[:change_status][:id])
sale_item.order_line_item_status_code_id = params[:change_status]
[:status_id]
sale_item.save
logger.info "Product added...success"
redirect_to :action => 'list'