显示视图中的“上一篇文章”和“下一篇文章”链接(嵌套资源)

在我的应用程序中,我想在文章显示视图的底部添加“上一篇文章”和“下一篇文章”链接。

这是我到目前为止,但我收到此错误:

undefined method `article_path' for #<#:0x007fd7cb8e5968> 

我知道路径必须看起来像这样(但我很难实现它)

 myapp/users/1/article/1 

新的铁路请帮助…

ROUTES

 resources users do resources articles end 

楷模

 class User < ActiveRecord::Base attr_accessible :name, :photo has_many :articles end class Article  ?", id).order("id ASC").first end def prev user.articles.where("id < ?", id).order("id DESC").first end end 

VIEWS

文章显示页面appname / users / 1 / articles / 1

    

CONTROLLER

 class ArticlesController < ApplicationController before_filter :get_publisher def get_user @user = User.find(params[:user_id]) end def show @article = @user.articles.find(params[:id]) end def index @articles = @user.articles end end 

简单地使用

 <%= link_to 'next', user_article_path(@user, @article.next) %> 

并通过类比来rest。