我对 Rails 完全陌生,并且在玩代码以使页面正常工作。链接localhost:3000/zombies/1有效(显示操作),但 localhost:3000/zombies(索引操作)无效。以下是我的路线和控制器:
路线是: 资源:僵尸
控制器是:
class ZombiesController < ApplicationController
before_filter :get_zombie_params
def index
respond_to do |format|
format.html # index.html.erb
format.json { render json: @zombies }
end
end
def show
@disp_zombie = increase_age @zombie, 15
@zombie_new_age = @disp_zombie
respond_to do |format|
format.html # show.html.erb
format.json { render json: @zombie }
end
end
def increase_age zombie, incr
zombie = zombie.age + incr
end
def get_zombie_params
@zombie=Zombie.find(params[:id])
@zombies = Zombie.all
end
end
为什么是这样?