Skip to content

Instantly share code, notes, and snippets.

@alecguintu
Last active August 29, 2015 14:01
Show Gist options
  • Save alecguintu/769754f640bdfa0b9d3e to your computer and use it in GitHub Desktop.
Save alecguintu/769754f640bdfa0b9d3e to your computer and use it in GitHub Desktop.
$('ul.links').on 'ajax:success', '.link', (evt, data, status, xhr) ->
console.log 'link clicked'
console.log $(this)
$('#this-form').bind 'ajax:success', (evt, data, status, xhr) ->
console.log 'form submitted'
# # When .link is clicked
# link clicked
# [a.link ...]
# form submitted
# # When form submitted
# form submitted
class TheController < Dashboard::ApplicationController
...
def update
...
respond_to do |format|
format.html { redirect_to :back }
format.json { render json: { success: true } }
end
end
def update_all
...
respond_to do |format|
format.html { redirect_to :back }
format.json { render json: { success: true } }
end
end
end
<%= form_tag update_all_objects_path, id: 'this-form', method: :patch, remote: true, data: {type: :json} %>
<ul>
<% @objects.each do |object| %>
<%= link_to 'Update', object_path(object), class: 'link', method: :patch, remote: true, data: {type: :json} %>
<% end %>
</ul>
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment