fixed pool sidebar in post/show
This commit is contained in:
@@ -91,16 +91,18 @@ class Pool < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def neighbor_posts(post)
|
||||
post_ids =~ /\A#{post.id} (\d+)|(\d+) #{post.id} (\d+)|(\d+) #{post.id}\Z/
|
||||
@neighbor_posts ||= begin
|
||||
post_ids =~ /\A#{post.id} (\d+)|(\d+) #{post.id} (\d+)|(\d+) #{post.id}\Z/
|
||||
|
||||
if $2 && $3
|
||||
{:previous => $2.to_i, :next => $3.to_i}
|
||||
elsif $1
|
||||
{:next => $1.to_i}
|
||||
elsif $4
|
||||
{:previous => $4.to_i}
|
||||
else
|
||||
nil
|
||||
if $2 && $3
|
||||
{:previous => $2.to_i, :next => $3.to_i}
|
||||
elsif $1
|
||||
{:next => $1.to_i}
|
||||
elsif $4
|
||||
{:previous => $4.to_i}
|
||||
else
|
||||
{}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -116,6 +118,7 @@ class Pool < ActiveRecord::Base
|
||||
|
||||
def reload(options = {})
|
||||
super
|
||||
@neighbor_posts = nil
|
||||
clear_post_id_array
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,17 @@
|
||||
<ul>
|
||||
<% post.pools.each do |pool| %>
|
||||
<li><span class="ui-icon ui-icon-circle-arrow-w"></span><span class="ui-icon ui-icon-circle-arrow-e"></span> <%= link_to pool_path(pool), pool.name %></li>
|
||||
<li>
|
||||
<% if pool.neighbor_posts(post)[:previous] %>
|
||||
<%= link_to "«".html_safe, post_path(pool.neighbor_posts(post)[:previous]) %>
|
||||
<% else %>
|
||||
«
|
||||
<% end %>
|
||||
<% if pool.neighbor_posts(post)[:next] %>
|
||||
<%= link_to "»".html_safe, post_path(pool.neighbor_posts(post)[:next]) %>
|
||||
<% else %>
|
||||
»
|
||||
<% end %>
|
||||
<%= link_to pool.name, pool_path(pool) %>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
@@ -7,9 +7,9 @@
|
||||
</section>
|
||||
|
||||
<% if @post.pools.any? %>
|
||||
<section>
|
||||
<section id="pool-sidebar">
|
||||
<h1>Pools</h1>
|
||||
<%= render "posts/partials/show/pools", :locals => {:post => @post} %>
|
||||
<%= render :partial => "posts/partials/show/pools", :locals => {:post => @post} %>
|
||||
</section>
|
||||
<% end %>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user