All i want to do in simple words: When input value is changed, i’ll put this value in db.
I want to add some ajax. I want to do this:
When I change my input value (focusout), i call some method, using get-parametr, my method looks like this:
def update_quantity
@cart = current_cart
@line_item = LineItem.find(params[:id])
respond_to do |format|
if @line_item.update_attribute(:quantity, params[:quantity]) #&& @cart.id == params[:cart]
format.html { redirect_to(@line_item, :notice => 'Line item was successfully updated.') }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @line_item.errors, :status => :unprocessable_entity }
end
end
end
This is test-work, so it maybe have some bad solutions, and my view looks like this:
%p
= line_item.art_name
= line_item.ART_ID
= line_item.art_code
×
.cart-quantity
= line_item.quantity
%input{ :class => "quantity", :value => line_item.quantity }
= link_to "обновить", :controller => "line_items", :action => "update_quantity", :id => line_item.id, :quantity => line_item.quantity, :cart => @cart.id
= line_item.total_price
As you see, I want to: when input focus is out, i get new hidden link, and call it, which calls method, which is written upper.
What i need to do? what files to create and where, and how to do this? Wanna some ajax)
All i want to do in simple words: When input value is changed, i’ll put this value in db.
You don’t need a hidden link to accomplish this. Use the onblur field of the html element:
In this example I inlined the javascript, it should really go in your application.js document.ready() block