Я совершенно новичок в рельсах и играю с кодом, чтобы заставить страницы работать. Ссылка 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
Почему это?
Zombie.find(params[:id])
, так иZombie.all
. Но в действии index у вас нет никаких параметров, поэтому вашZombie.find(params[:id]
выдает вам ошибкуActiveRecord
. - person mehulkar   schedule 24.10.2012