views:

194

answers:

2

i m using rails 2.3.3 and web browser Firefox i have added ajax and java script and it is working too but i have to reload the page every time when i press Add to Cart button to show item additionn in the side bar it don’t show it without reloading.

anyone please help me how can it show item addition in side bar when i press Add to Cart button with out reloading the page?

A: 

The standard ajax helper methods are link_to_remote, form_remote_tag, form_remote_for, button_for_remote. (I might have missed a few.) If you're not using one of them, you could be doing something wrong.

If you're using one of the helper methods with remote as part of the name, you might be missing the update option or the update option is pointed to the wrong html element.

For a form_remote_tag helper:

form_remote_tag(:url => {:controller => controller_name, :action => action_name, :id => id},
:update => element_to_update)

The element_to_update should be the html element's id that you're updating.

Jim
i m using the following form_remote_tag method but i m not using any update option could u please tell me how to update it? i m learning agile web development with rails 2.3.3 but it is also not using any update option. <% form_remote_tag :url => { :action => 'add_to_cart', :id => product } do %> <%= submit_tag "Add to Cart" %> <% end %>
Zeshansari
I updated my answer.
Jim
A: 

If you haven't already done so, install Firebug for Firefox, for these reasons:

  • it'll tell you if you have a Javascript error.
  • it'll show you if your Ajax request is being received and its contents.
  • you can inspect your page elements such as the cart to see if it's set to be shown, if the ID is correct, etc. in a much faster way than browsing through the source.
  • and more (CSS, etc).

If you can't figure it out by looking at the Firebug console, and since you're following a tutorial, why don't you download the Depot source code and compare it with your own to see what you're doing wrong.

If you have the book, the complete source is listed at the end of the book. You can also download the source from here.

JRL
i hve instal firebug already but it is not refreshing Add to Cart on the sidebar itself.i have to hit refresh button to see my cart on sidebar.i need to know how can i update this form_remote_tag? i don't know its syntex u please tell me.<% form_remote_tag :url => { :action => 'add_to_cart', :id => product } do %> <%= submit_tag "Add to Cart" %>
Zeshansari