Я работаю над комментариями в приложении для управления рецептами. Я могу создать, удалить и получить правильную форму редактирования комментария, но не могу понять, как на самом деле отправить редактирование. Вот мой код до сих пор. Это немного грязно, любая помощь будет принята с благодарностью.
Это моя функция, которая корректно заменяет комментарий формой, отмена корректно отменяет изменение, весь закомментированный код и код ajax являются попытками ...
$(function submitEdit(){
$('body').on("click",'button#submit_edit_comment', function(){
var editedComment = new Object();
editedComment.description = $('#comment_description').val();
editedComment.rating = $('#comment_rating').val();
$.ajax({
url: this.formAction,
type: "PATCH",
data: JSON.stringify(editedComment),
success: function(response) {
console.log(response)
debugger
//$('div.edit_comment_form').replaceWith(response)
}
});
});
})
Мое сообщение об ошибке: ActionController :: ParameterMissing в CommentsController # update
-параметр отсутствует или значение пусто: комментарий
Вот метод Контроллера:
def update
comment = find_by_id(Comment)
respond_to do |format|
if comment.update(comment_params)
format.html { redirect_to recipe_path(comment.recipe), notice: 'Comment was successfully created.' }
format.json { render json: comment.to_json(only: [:rating, :description, :id, :recipe_id],
include: [user: { only: [:name]}])}
else
format.html { redirect_to recipe_path(comment.recipe), alert: "You can't leave the comment box blank. Please try again!" }
format.json { render json: comment.errors, status:400 }
end
end
end
и мои комментарии_параметры:
def comment_params
params.require(:comment).permit(:rating, :description, :user)
end
Если я удаляю require (: comment), ошибка не в методе обновления ошибки для NIL
Не уверен, как решить эту проблему.
Мое репо можно найти по адресу:
https://github.com/Bartekswistak/fun_guy_chef/tree/jquery