From f695db4bb1842fb7e19be823d788c737649d16f3 Mon Sep 17 00:00:00 2001 From: Absurdon Date: Thu, 3 May 2018 19:25:50 +0200 Subject: [PATCH] Fix updating of custom urls --- app/controllers/custom_urls_controller.rb | 7 +++-- app/views/custom_urls/_controls.js.erb | 34 +++++++++++------------ 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/app/controllers/custom_urls_controller.rb b/app/controllers/custom_urls_controller.rb index 8105b41..a367388 100644 --- a/app/controllers/custom_urls_controller.rb +++ b/app/controllers/custom_urls_controller.rb @@ -35,10 +35,13 @@ class CustomUrlsController < ApplicationController url = CustomUrl.find(params[:id]) rescue nil if url - if url.update_attributes(params[:custom_url]) + url.article_id = params[:custom_url][:article_id] + url.name= params[:custom_url][:name] + if url.save response[:status] = 200 response[:message] = 'Successfully updated!' - response[:obj] = url + resobj = {name: url.name, title: url.article.title} + response[:obj] = resobj else response[:status] = 400 message = 'Update failed! Errors:' diff --git a/app/views/custom_urls/_controls.js.erb b/app/views/custom_urls/_controls.js.erb index 907b1ff..7b437d2 100644 --- a/app/views/custom_urls/_controls.js.erb +++ b/app/views/custom_urls/_controls.js.erb @@ -1,32 +1,32 @@ showEdit = function (url_id) { - var parent = $('#' + url_id); - parent.find('> td').toggleClass('hidden'); + var parent = $('#' + url_id); + parent.find('> td').toggleClass('hidden'); }; submitEdit = function (url_id) { - var parent = $('#' + url_id); - var form = parent.find('form'); + var parent = $('#' + url_id); + var form = parent.find('form'); - $.post('<%= custom_urls_path %>/' + url_id, form.serialize()) - .done(function (data) { - var nameField = parent.children('.name'); - var articleField = parent.children('.article'); + $.post('<%= custom_urls_path %>/' + url_id, form.serialize()) + .done(function (data) { + var nameField = parent.children('.name'); + var articleField = parent.children('.article'); - nameField.text(data.obj.name); - articleField.text(data.obj.title); - parent.find('> td').toggleClass('hidden'); + nameField.text(data.obj.name); + articleField.text(data.obj.title); + parent.find('> td').toggleClass('hidden'); - alert(data.message); - }).fail(function (errorRes) { - var error = JSON.parse(errorRes.responseText); - alert(error.message); - }); + alert(data.message); + }).fail(function (errorRes) { + var error = JSON.parse(errorRes.responseText); + alert(error.message); + }); } deleteUrl = function (url_id) { var confirmed = confirm('Are you sure you want to delete this item?'); - if(confirmed) { + if (confirmed) { $.ajax({ url: '<%= custom_urls_path %>/' + url_id, type: 'DELETE'