我生成了一个脚手架,并创建了一个临时应用程序。我想在应用程序的任何地方(在 application.html.erb 内)的侧边栏上列出脚手架项目。我在application.html.erb中的左栏看起来像这样:
> <div id="leftcolumn">
> <% @items.each do |link| %>
> <%= link_to link.title, link %>
> <% end %>
> </div>
单击每个项目将导致它的 Show 方法。运行之后,每当我尝试访问任何项目的任何方法时,它都会向我显示以下错误:
> NoMethodError in Items#show
>
> Showing F:/Rails/items-list/app/views/layouts/application.html.erb
> where line #17 raised:
>
> You have a nil object when you didn't expect it!
> You might have expected an instance of Array.
> The error occurred while evaluating nil.each
后面的代码是左列的代码。我该如何解决?