1

I guess this question is similar to this one, but asking again as it has not yet been answered.

In my rails application, I have a view that contains a list of links that load content via ajax.

Here is the partial for the link

<%= link_to(story.title, {:controller=>"story", :id=>story.id}, :remote => true , :method=>'get', :class=>'story-link') %>

This remote link works fine and loads content via AJAX when the view is loaded via HTTP.

The view also has a small remote form which upon submission results in a new link added to the view. However, as this new link is loaded via AJAX, it does not work (i.e. does not load content via AJAX).

Moreover, when I refresh the view in the browser the new link works fine. I believe that the appropriate event binding does not take place when the link is loaded via AJAX. How can I solve this problem?

Community
  • 1
  • 1
Ankit
  • 6,772
  • 11
  • 48
  • 84

1 Answers1

0

You either need to use delegated event handling for the form submission js, or re-register the form submission event(s) when the content is reloaded.

Brad Werth
  • 17,411
  • 10
  • 63
  • 88
  • I am a newbie to web development, so I do not fully understand your answer. I am not having a form. Rather I have links. How do I re-register? For the links loaded as part of the view via HTTP, the `:remote=>true` automatically registers the appropriate events on the links, I believe! – Ankit Dec 30 '12 at 05:06