controllers: set @current_item globally in respond_with.
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -79,7 +79,7 @@
|
||||
<%= yield :html_header %>
|
||||
<%= raw Danbooru.config.custom_html_header_content %>
|
||||
</head>
|
||||
<%= tag.body **body_attributes(CurrentUser.user, @current_item) do %>
|
||||
<%= tag.body **body_attributes(CurrentUser.user, params, @current_item) do %>
|
||||
<%= render "news_updates/listing" %>
|
||||
|
||||
<header id="top">
|
||||
|
||||
Reference in New Issue
Block a user