into cart format.js { @current_item = @line_item} Respond to the JS request, by convention, go to execute js.erb with the same name (in this example: create.js.erb) 12年10月20日星期六
” and ‘ ’ are very important) Most important, $('#cart').html(_cart.html.erb we returned), it is a jQuery syntax which put the HTML we return into the element with id cart, You can write it in traditional javascript syntax, document.getElementById(“cart”).innerHTML = <%= xxx %>; 12年10月20日星期六
is belong to line_itmes_controller when we click Add to cart button 2. line_items_controller JS processes the we made and execute create.js.erb 3. render @cart is Ruby code which simply generates some HTML using _cart.html.erb 4. Put the HTML generated into the the DOM element with id of cart 5. The HTML in the page will be dynamically changed. 12年10月20日星期六