artists/show: refactor post previews.
This commit is contained in:
@@ -44,7 +44,6 @@ class ArtistsController < ApplicationController
|
|||||||
|
|
||||||
def show
|
def show
|
||||||
@current_item = @artist = Artist.find(params[:id])
|
@current_item = @artist = Artist.find(params[:id])
|
||||||
@post_set = PostSets::Artist.new(@artist)
|
|
||||||
respond_with(@artist)
|
respond_with(@artist)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -80,7 +79,6 @@ class ArtistsController < ApplicationController
|
|||||||
redirect_to artist_path(@artist)
|
redirect_to artist_path(@artist)
|
||||||
else
|
else
|
||||||
@artist = Artist.new(name: params[:name])
|
@artist = Artist.new(name: params[:name])
|
||||||
@post_set = PostSets::Artist.new(@artist)
|
|
||||||
respond_with(@artist)
|
respond_with(@artist)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,24 +0,0 @@
|
|||||||
module PostSets
|
|
||||||
class Artist < PostSets::Post
|
|
||||||
attr_reader :artist
|
|
||||||
|
|
||||||
def initialize(artist)
|
|
||||||
super(artist.name)
|
|
||||||
@artist = artist
|
|
||||||
end
|
|
||||||
|
|
||||||
def posts
|
|
||||||
@posts ||= begin
|
|
||||||
query = ::Post.tag_match(@artist.name).where("true /* PostSets::Artist#posts */").limit(10)
|
|
||||||
query.each # hack to force rails to eager load
|
|
||||||
query
|
|
||||||
end
|
|
||||||
rescue ::Post::SearchError
|
|
||||||
::Post.none
|
|
||||||
end
|
|
||||||
|
|
||||||
def presenter
|
|
||||||
::PostSetPresenters::Post.new(self)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@@ -12,15 +12,17 @@
|
|||||||
|
|
||||||
<%= yield %>
|
<%= yield %>
|
||||||
|
|
||||||
<div class="recent-posts">
|
<% if @artist.tag.present? && @artist.tag.post_count > 0 %>
|
||||||
<h2>Recent Posts</h2>
|
<div class="recent-posts">
|
||||||
|
<h2>Recent Posts <%= link_to "»", posts_path(tags: @artist.name) %></h2>
|
||||||
|
|
||||||
<%= render "posts/partials/common/inline_blacklist" %>
|
<%= render "posts/partials/common/inline_blacklist" %>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<%= @post_set.presenter.post_previews_html(self) %>
|
<%= post_previews_html(@artist.tag.posts.limit(8), tags: @artist.name) %>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user