2

我一直在努力纠正nil:NilClass 的“未定义方法名称”的问题name'" when I have installed the kaminari gem.
Error message: undefined method

Extracted source (around line #3):

<article class="body">
  <header>
    <h1><%= @news_item.name %></h1>
 </header>
 <%= @news_item.body %>
</article>

我的路线文件中有这个:

resources :news, :only => [:index, :show]

namespace :admin do
  resources :news_items
end

新闻项目的部分:

   %article.body
    = @news_item.name
    = @news_item.body 

新闻控制器:

class NewsController < ApplicationController
  def index
    @news_items = NewsItem.order("id").page(params[:page]).per(5) 

    respond_to do |format|
      format.html #do nothing.
      format.json { render :json => @news_items.to_json }
      format.xml { render :xml => @news_items.to_xml }
    end
  end
  def show
    @news_item = NewsItem.find params[:id]
  end

end

对于新闻#index:

= paginate @news_items
= render :partial => "/shared/news_item", :collection => @news_items

谁能确定为什么我无法解决这个没有方法错误的问题?

谢谢

大卫

4

0 回答 0