我在routes.rb中有这个设置:
resources :users do
resources :images do
resources :comments
end
end
当我从ImagesController加载show动作时,模板文件中的内容如下:
...
= render 'comments/form', :@comment => @image.comments.new
...
并且在评论/表单文件中如下:
= form_for [@comment.commentable, @comment] do |f|
.field
= f.text_field :body
.actions
= f.submit 'Comment'
和表演动作:
def show
@user = User.find(params[:user_id])
@image = @user.images.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render :json => @image }
end
end
但是当我在浏览器中加载这个页面时,我得到了这个错误:
undefined method `image_comments_path' for #<#<Class:0x007feb48488128>:0x007feb48399668>
为什么 Rails 返回此错误消息?