So, I am creating a blog engine that has / articles / then -the-article-permalink as its URL structure. I need to have the previous and next links that will go to the next pub_date article, my code looks like this:
In my articles # show
@article = Article.find_by_permalink(params[:id]) @prev_article = Article.find(:first, :conditions => [ "pub_date < ?", @article.pub_date]) @next_article = Article.find(:first, :conditions => [ "pub_date > ?", @article.pub_date])
And in my show.html.erb
<%= link_to "Next", article_path(@next_article) %> <%= link_to 'Prev', article_path(@prev_article) %>
In my article model, I have the following:
def to_param self.permalink end
I get the following error message:
article_url failed to generate from {:action=>"show", :controller=>"articles", :id=>nil}, expected: {:action=>"show", :controller=>"articles"}, diff: {:id=>nil}
Without the next and the next, everything works fine, but I have no idea why this is not working. Anyone want to help?
source share