title: Rails skip over/ignore data for links?
body: <p>So I am setting up previous post links in my Rails app and have the following in my show:</p>
  
  <pre><code>&lt;% if @post.previous.blog_key == 'blog' &amp;&amp; @post.previous.visible == true %&gt;
   &lt;%= link_to 'previous post', blog_post_path(@post.previous.url_name%&gt;
  &lt;% else %&gt;
   &lt;%= link_to 'Home', '/blog/home' %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>Then in my model I have:</p>
  
  <pre><code>def previous
   SpudPost.where(["published_at &lt; ?", published_at]).last
  end
  
  def next
   SpudPost.where(["published_at &gt; ?", published_at]).first
  end
  </code></pre>
  
  <p>What I'm trying to do is only have the previous links to go to those blog posts that are marked as having a blog_key that says blog AND marked to be visible. If it's not blog/false then ignore it and go to the next one that says blog and visible. </p>
  
  <p>The problem is that it doesn't go to the next one that says blog/true. If the next one says blog_key == 'news' then it applies to 'Home'. Should it just be another filter within the previous/next methods instead?</p>