Last active
July 10, 2017 10:59
-
-
Save Evanto/7b147733f585ec276d741d279fa0f007 to your computer and use it in GitHub Desktop.
форма не появляется по клику на edit свежедобавленного ответа
This file contains 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
# Place all the behaviors and hooks related to the matching controller here. | |
# All this logic will automatically be available in application.js. | |
# You can use CoffeeScript in this file: http://coffeescript.org/ | |
# Объявляем функцию ready, внутри которой можно поместить обработчики событий и другой код, | |
# который должен выполняться при загрузке страницы | |
ready = -> # оборачиваем все до строки 15 в функцию ready | |
# Это наш функция-обработчик, перенесенная сюда из document.ready ($ ->) | |
$('.edit-answer-link').click (e) -> # событие ниже работает по клику на элемент с классом .edit-answer-link | |
# (почитать, что делает событие click в jquery) https://api.jquery.com/click/ | |
e.preventDefault(); # что это означает? прочитать | |
$(this).hide(); # хайдит ссылку .edit-answer-link. | |
answer_id = $(this).data('answerId'); # получает данные (id) из data и сохраняет в переменную answer_id | |
# $('form#edit-form').hide(); # пометить форму редактирования ответа айлишником и вписать сюда. | |
# тут хайдим все формы кроме той что соответствует айди ответа у которого кликнули edit | |
$('form#edit-answer-' + answer_id).show() # показывает форму по клику | |
$(document).ready(ready) # вешаем функцию ready на событие document.ready | |
$(document).on('turbolinks:load', ready) # вешаем функцию ready на событие page:load | |
$(document).on('turbolinks:update', ready) # вешаем функцию ready на событие page:update | |
# хендлером называется функция, повешенная на какое-то событие (исполняемая по событию) |
This file contains 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
# Place all the behaviors and hooks related to the matching controller here. | |
# All this logic will automatically be available in application.js. | |
# You can use CoffeeScript in this file: http://coffeescript.org/ | |
ready = -> | |
# Это наш обработчик, перенесенный сюда из document.ready ($ ->) | |
$('.answers').on 'click', '.edit-answer-link', (e) -> | |
e.preventDefault(); | |
$(this).hide(); | |
answer_id = $(this).data('answerId') | |
$('form#edit-answer-' + answer_id).show() | |
$(document).on('turbolinks:load', ready) | |
$(document).on('page:load', ready) | |
$(document).on('page:update', ready) |
This file contains 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
<% if @answer.errors.present? %> | |
<% @answer.errors.full_messages.each do |message| %> | |
$('.errors').html('<%= j message %>'); | |
<% end %> | |
<% else %> | |
$('#answer<%= @answer.id %>').replaceWith('<%= j render @answer %>'); | |
$('.answers').html('<%= j render 'answers/answers' %>'); | |
<% end %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment