diff --git a/app/assets/javascripts/posts.js.erb b/app/assets/javascripts/posts.js.erb index 74c73164a..f4581e5ce 100644 --- a/app/assets/javascripts/posts.js.erb +++ b/app/assets/javascripts/posts.js.erb @@ -154,7 +154,7 @@ Danbooru.Post.initialize_similar = function() { $("#similar-button").click(function(e) { - $.get("/iqdb_queries", {"variant": "xhr", "url": $("#post_source").val()}).done(function(html) {$("#iqdb-similar").html(html).show()}); + $.get("/iqdb_queries", {"url": $("#post_source").val()}).done(function(html) {$("#iqdb-similar").html(html).show()}); e.preventDefault(); }); } diff --git a/app/assets/javascripts/uploads.js b/app/assets/javascripts/uploads.js index c18dabdd0..b9cc1bdbe 100644 --- a/app/assets/javascripts/uploads.js +++ b/app/assets/javascripts/uploads.js @@ -61,7 +61,7 @@ Danbooru.Upload.initialize_iqdb_source = function() { if (/^https?:\/\//.test($("#normalized_url").val())) { - $.get("/iqdb_queries", {"variant": "xhr", "url": $("#normalized_url").val()}).done(function(html) {$("#iqdb-similar").html(html)}); + $.get("/iqdb_queries", {"url": $("#normalized_url").val()}).done(function(html) {$("#iqdb-similar").html(html)}); } } @@ -77,7 +77,7 @@ Danbooru.Upload.initialize_similar = function() { $("#similar-button").click(function(e) { - $.get("/iqdb_queries", {"variant": "xhr", "url": $("#upload_source").val()}).done(function(html) {$("#iqdb-similar").html(html).show()}); + $.get("/iqdb_queries", {"url": $("#upload_source").val()}).done(function(html) {$("#iqdb-similar").html(html).show()}); e.preventDefault(); }); } diff --git a/app/controllers/iqdb_queries_controller.rb b/app/controllers/iqdb_queries_controller.rb index c076dd420..fe2b24b10 100644 --- a/app/controllers/iqdb_queries_controller.rb +++ b/app/controllers/iqdb_queries_controller.rb @@ -1,5 +1,6 @@ class IqdbQueriesController < ApplicationController respond_to :html, :json + before_action :detect_xhr def show if params[:url] @@ -15,10 +16,8 @@ class IqdbQueriesController < ApplicationController end respond_with(@matches) do |fmt| - fmt.html - - fmt.html.xhr do - render layout: false + fmt.html do |html| + html.xhr { render layout: false} end fmt.json do @@ -26,4 +25,12 @@ class IqdbQueriesController < ApplicationController end end end + +private + + def detect_xhr + if request.xhr? + request.variant = :xhr + end + end end diff --git a/app/views/iqdb_queries/show+xhr.html.erb b/app/views/iqdb_queries/show.html+xhr.erb similarity index 100% rename from app/views/iqdb_queries/show+xhr.html.erb rename to app/views/iqdb_queries/show.html+xhr.erb