Last active
August 29, 2015 13:55
-
-
Save calebhearth/8710014 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SectionsController < ApplicationController | |
def update | |
section = course.sections.find(params[:id]) | |
section.update(section_params) | |
render section_json(section) | |
end | |
private | |
def section_json(section) | |
section_html = render_to_string section, location: nil, formats: [:html] | |
section_form_html = render_to_string 'sections/_form', locals: { section: section }, layout: false | |
{ json: { section_html: section_html, section_form_html: section_form_html } } | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ -> | |
$('#sections-list').on 'ajax:success', 'form.edit_section', Callbacks.reloadSectionAndForm | |
Callbacks = | |
reloadSectionAndForm: (e, json) -> | |
parentElement = $(e.delegateTarget) | |
Callbacks._replaceFromJson(parentElement, json.section_html) | |
Callbacks._replaceFromJson(parentElement, json.section_form_html) | |
Callbacks._resetToggles | |
_replaceFromJson: (parentElement, html) -> | |
element = $(html) | |
parentElement.find("##{element.attr('id')}").replaceWith(element) | |
_resetToggles: -> | |
$('[data-toggle-target]').each -> | |
$(@).toggleTarget() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment