0

I'm trying to add AJAX for delete action of my controller following railscast 136 - jQuery AJAX revised

It deletes element I choose but it doesn't disappear from the page. The problem is that I can't figure out how to create propper jQuery selector.

I would be ok to use $('#slide_<%= @destroyed_slide_id %>').remove(); for just one slide (no array) but my controller provides @destroyed_slides_ids array. How to create selector from it ?

2
  • Do not edit your question’s title with “solved”, instead accept an answer to mark it as so. You can accept your own answer to a question after 48 hours. Commented Apr 18, 2014 at 1:46
  • Those 48 hours are exactly the reason why I added (solved) tag. Commented Apr 18, 2014 at 8:54

2 Answers 2

1

Just loop over each id in the @destroyed_slides_ids array

<% @destroyed_slides_ids.each do |id| %>
    $('#slide_<%= id %>').remove();
<% end %>
Sign up to request clarification or add additional context in comments.

Comments

0

I found a better way. jQuery selector can be used to select multiple elements at once:

$('<%= @destroyed_slides_ids.map { |slide| "#slide_" + slide.to_s }.join(', ') %>').remove();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.