0

wostatusesというテーブルの2番目のインデックスファイルを追加しています。最初のインデックス(index.html.erb)は正常に機能します。ただし、2番目のインデックス(index2.html.erb)は、次の行で「nil.eachの評価中にエラーが発生しました」を取得します。

<% @wostatuses.each do |wostatus| %>

コントローラには次のものがあります。

class WostatusesController < ApplicationController
# GET /wostatuses
# GET /wostatuses.json
def index
  @wostatuses = Wostatus.order("position")

  respond_to do |format|
    format.html # index.html.erb
    format.json { render json: @wostatuses }
  end
 end

index.html.erbとindex2.html.erbには次のものがあります。

  <% @wostatuses.each do |wostatus| %>

ルートでは、私は持っています:

  get "wostatuses/index"
  get "wostatuses/index2"

助けてくれてありがとう!!

アップデート -

<% Wostatus.find_each do |wostatus| %> worked!!!!

ただし、wostatus.position順に並べられたレコードが必要です。それ、どうやったら出来るの?

4

1 に答える 1

0

同じコードのindex1を使用して、コントローラーでindex2に対してアクションを実行する必要があります。また、共通の機能を備えたメソッドを作成し、両方のアクションでそのメソッドを使用して、再利用可能なコードを作成することもできます。

于 2012-12-16T21:43:53.410 に答える