diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index c7b68906d..08eda01a2 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -24,11 +24,13 @@ class ApplicationController < ActionController::Base private - def respond_with(*options, &block) - if params[:action] == "index" && is_redirect?(options[0]) - redirect_to_show(options[0]) + def respond_with(subject, *options, &block) + @current_item = subject + + if params[:action] == "index" && is_redirect?(subject) + redirect_to_show(subject) else - super(*options, &block) + super end end diff --git a/app/controllers/artists_controller.rb b/app/controllers/artists_controller.rb index a57187cc2..c42eef561 100644 --- a/app/controllers/artists_controller.rb +++ b/app/controllers/artists_controller.rb @@ -39,7 +39,7 @@ class ArtistsController < ApplicationController end def show - @current_item = @artist = Artist.find(params[:id]) + @artist = Artist.find(params[:id]) respond_with(@artist) end diff --git a/app/controllers/bans_controller.rb b/app/controllers/bans_controller.rb index 94db739e3..3a8b1645e 100644 --- a/app/controllers/bans_controller.rb +++ b/app/controllers/bans_controller.rb @@ -19,7 +19,7 @@ class BansController < ApplicationController end def show - @current_item = @ban = Ban.find(params[:id]) + @ban = Ban.find(params[:id]) respond_with(@ban) end diff --git a/app/controllers/bulk_update_requests_controller.rb b/app/controllers/bulk_update_requests_controller.rb index 740b38c8c..9b8ad9b1b 100644 --- a/app/controllers/bulk_update_requests_controller.rb +++ b/app/controllers/bulk_update_requests_controller.rb @@ -15,7 +15,7 @@ class BulkUpdateRequestsController < ApplicationController end def show - @current_item = @bulk_update_request = BulkUpdateRequest.find(params[:id]) + @bulk_update_request = BulkUpdateRequest.find(params[:id]) respond_with(@bulk_update_request) end diff --git a/app/controllers/dmails_controller.rb b/app/controllers/dmails_controller.rb index ee72408de..d76e19985 100644 --- a/app/controllers/dmails_controller.rb +++ b/app/controllers/dmails_controller.rb @@ -24,7 +24,7 @@ class DmailsController < ApplicationController end def show - @current_item = @dmail = Dmail.find(params[:id]) + @dmail = Dmail.find(params[:id]) check_privilege(@dmail) @dmail.mark_as_read! respond_with(@dmail) diff --git a/app/controllers/favorite_groups_controller.rb b/app/controllers/favorite_groups_controller.rb index 91fed24dd..a66a93d95 100644 --- a/app/controllers/favorite_groups_controller.rb +++ b/app/controllers/favorite_groups_controller.rb @@ -11,7 +11,7 @@ class FavoriteGroupsController < ApplicationController def show limit = params[:limit].presence || CurrentUser.user.per_page - @current_item = @favorite_group = FavoriteGroup.find(params[:id]) + @favorite_group = FavoriteGroup.find(params[:id]) check_read_privilege(@favorite_group) @posts = @favorite_group.posts.paginate(params[:page], limit: limit, count: @favorite_group.post_count) diff --git a/app/controllers/forum_topics_controller.rb b/app/controllers/forum_topics_controller.rb index 6c0e42559..fd8622aa2 100644 --- a/app/controllers/forum_topics_controller.rb +++ b/app/controllers/forum_topics_controller.rb @@ -32,7 +32,6 @@ class ForumTopicsController < ApplicationController end def show - @current_item = @forum_topic if request.format == Mime::Type.lookup("text/html") @forum_topic.mark_as_read!(CurrentUser.user) end diff --git a/app/controllers/pools_controller.rb b/app/controllers/pools_controller.rb index 8d3877c26..322806873 100644 --- a/app/controllers/pools_controller.rb +++ b/app/controllers/pools_controller.rb @@ -33,7 +33,7 @@ class PoolsController < ApplicationController def show limit = params[:limit].presence || CurrentUser.user.per_page - @current_item = @pool = Pool.find(params[:id]) + @pool = Pool.find(params[:id]) @posts = @pool.posts.paginate(params[:page], limit: limit, count: @pool.post_count) respond_with(@pool) end diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 270e36666..6e116b276 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -19,7 +19,7 @@ class PostsController < ApplicationController end def show - @current_item = @post = Post.find(params[:id]) + @post = Post.find(params[:id]) @comments = @post.comments @comments = @comments.includes(:creator) diff --git a/app/controllers/tag_aliases_controller.rb b/app/controllers/tag_aliases_controller.rb index 7f6ae076c..acc86b969 100644 --- a/app/controllers/tag_aliases_controller.rb +++ b/app/controllers/tag_aliases_controller.rb @@ -3,7 +3,7 @@ class TagAliasesController < ApplicationController respond_to :html, :xml, :json, :js def show - @current_item = @tag_alias = TagAlias.find(params[:id]) + @tag_alias = TagAlias.find(params[:id]) respond_with(@tag_alias) end diff --git a/app/controllers/tag_implications_controller.rb b/app/controllers/tag_implications_controller.rb index fab6d579d..0b3f1f077 100644 --- a/app/controllers/tag_implications_controller.rb +++ b/app/controllers/tag_implications_controller.rb @@ -3,7 +3,7 @@ class TagImplicationsController < ApplicationController respond_to :html, :xml, :json, :js def show - @current_item = @tag_implication = TagImplication.find(params[:id]) + @tag_implication = TagImplication.find(params[:id]) respond_with(@tag_implication) end diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index aac893786..4a3cd5665 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -3,7 +3,7 @@ class TagsController < ApplicationController respond_to :html, :xml, :json def edit - @current_item = @tag = Tag.find(params[:id]) + @tag = Tag.find(params[:id]) check_privilege(@tag) respond_with(@tag) end @@ -26,7 +26,7 @@ class TagsController < ApplicationController end def show - @current_item = @tag = Tag.find(params[:id]) + @tag = Tag.find(params[:id]) respond_with(@tag) end diff --git a/app/controllers/uploads_controller.rb b/app/controllers/uploads_controller.rb index 0c3057b51..eff7fefa3 100644 --- a/app/controllers/uploads_controller.rb +++ b/app/controllers/uploads_controller.rb @@ -28,7 +28,7 @@ class UploadsController < ApplicationController end def show - @current_item = @upload = Upload.find(params[:id]) + @upload = Upload.find(params[:id]) respond_with(@upload) do |format| format.html do if @upload.is_completed? && @upload.post_id diff --git a/app/controllers/user_feedbacks_controller.rb b/app/controllers/user_feedbacks_controller.rb index 0d5ae4d10..2c2ee5dc6 100644 --- a/app/controllers/user_feedbacks_controller.rb +++ b/app/controllers/user_feedbacks_controller.rb @@ -14,7 +14,7 @@ class UserFeedbacksController < ApplicationController end def show - @current_item = @user_feedback = UserFeedback.visible.find(params[:id]) + @user_feedback = UserFeedback.visible.find(params[:id]) respond_with(@user_feedback) end diff --git a/app/controllers/user_name_change_requests_controller.rb b/app/controllers/user_name_change_requests_controller.rb index e4c58c699..40df71d1b 100644 --- a/app/controllers/user_name_change_requests_controller.rb +++ b/app/controllers/user_name_change_requests_controller.rb @@ -14,7 +14,7 @@ class UserNameChangeRequestsController < ApplicationController end def show - @current_item = @change_request = UserNameChangeRequest.find(params[:id]) + @change_request = UserNameChangeRequest.find(params[:id]) check_privileges!(@change_request) respond_with(@change_request) end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index d8f480886..42728b7cc 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -39,7 +39,7 @@ class UsersController < ApplicationController end def show - @current_item = @user = User.find(params[:id]) + @user = User.find(params[:id]) respond_with(@user, methods: @user.full_attributes) end diff --git a/app/controllers/wiki_page_versions_controller.rb b/app/controllers/wiki_page_versions_controller.rb index 8b57fe1e6..eb5084002 100644 --- a/app/controllers/wiki_page_versions_controller.rb +++ b/app/controllers/wiki_page_versions_controller.rb @@ -8,7 +8,7 @@ class WikiPageVersionsController < ApplicationController end def show - @current_item = @wiki_page_version = WikiPageVersion.find(params[:id]) + @wiki_page_version = WikiPageVersion.find(params[:id]) respond_with(@wiki_page_version) end diff --git a/app/controllers/wiki_pages_controller.rb b/app/controllers/wiki_pages_controller.rb index 318da3801..a3ed76e0d 100644 --- a/app/controllers/wiki_pages_controller.rb +++ b/app/controllers/wiki_pages_controller.rb @@ -26,7 +26,6 @@ class WikiPagesController < ApplicationController def show @wiki_page, found_by = WikiPage.find_by_id_or_title(params[:id]) - @current_item = @wiki_page if request.format.html? && @wiki_page.blank? && found_by == :title @wiki_page = WikiPage.new(title: params[:id]) respond_with @wiki_page, status: 404 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 7af227464..81b9df449 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -214,10 +214,10 @@ module ApplicationHelper render "table_builder/table", table: table end - def body_attributes(user = CurrentUser.user, current_item = nil) + def body_attributes(user, params, current_item = nil) current_user_data_attributes = data_attributes_for(user, "current-user", current_user_attributes) - if current_item.present? + if params[:action] == "show" && current_item.present? model_name = current_item.model_name.singular.dasherize model_attributes = current_item.html_data_attributes current_item_data_attributes = data_attributes_for(current_item, model_name, model_attributes) diff --git a/app/views/layouts/default.html.erb b/app/views/layouts/default.html.erb index fd2901bc3..6dd4f6431 100644 --- a/app/views/layouts/default.html.erb +++ b/app/views/layouts/default.html.erb @@ -79,7 +79,7 @@ <%= yield :html_header %> <%= raw Danbooru.config.custom_html_header_content %> -<%= tag.body **body_attributes(CurrentUser.user, @current_item) do %> +<%= tag.body **body_attributes(CurrentUser.user, params, @current_item) do %> <%= render "news_updates/listing" %>