Generating URLs when not using an integer as an id?

Posted by Synthesezia on Stack Overflow See other posts from Stack Overflow or by Synthesezia
Published on 2010-04-02T19:57:52Z Indexed on 2010/04/02 20:03 UTC
Read the original article Hit count: 255

Filed under:
|

So I'm building a blog engine which has /articles/then-the-article-permalink as it's URL structure. I need to have prev and next links which will jump to the next article by pub_date, 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_picture = 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 articles model I have this:

def to_param
    self.permalink
end

The specific error message I get is:

article_url failed to generate from {:action=>"show", :controller=>"articles", :id=>nil}, expected: {:action=>"show", :controller=>"articles"}, diff: {:id=>nil}

Without the prev and next everything is working fine but I'm out of ideas as to why this isn't working. Anyone want to helo?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about rails