【发布时间】:2016-02-24 15:56:51
【问题描述】:
我使用 rails 生成器生成了一个脚手架,并在下面创建了控制器。
当我尝试检查它是否有效时,我收到一条错误消息:
ActiveRecord::RecordNotFound at /org_checklists/index
Couldn't find OrgChecklist with 'id'=index
我最近遇到了同样的错误(下面的问题),解决方案是从before action 中删除:index。但是,此控制器在 before action 中不包含该操作。
Rails 4 error - rails Couldn't find User with 'id'=index
class OrgChecklistsController < ApplicationController
before_action :set_org_checklist, only: [:show, :edit, :update, :destroy]
# GET /org_checklists
# GET /org_checklists.json
def index
@org_checklists = OrgChecklist.all
authorize @org_checklists
end
# GET /org_checklists/1
# GET /org_checklists/1.json
def show
end
# GET /org_checklists/new
def new
@org_checklist = OrgChecklist.new
end
# GET /org_checklists/1/edit
def edit
end
# POST /org_checklists
# POST /org_checklists.json
def create
@org_checklist = OrgChecklist.new(org_checklist_params)
respond_to do |format|
if @org_checklist.save
format.html { redirect_to @org_checklist, notice: 'Org checklist was successfully created.' }
format.json { render :show, status: :created, location: @org_checklist }
else
format.html { render :new }
format.json { render json: @org_checklist.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /org_checklists/1
# PATCH/PUT /org_checklists/1.json
def update
respond_to do |format|
if @org_checklist.update(org_checklist_params)
format.html { redirect_to @org_checklist, notice: 'Org checklist was successfully updated.' }
format.json { render :show, status: :ok, location: @org_checklist }
else
format.html { render :edit }
format.json { render json: @org_checklist.errors, status: :unprocessable_entity }
end
end
end
# DELETE /org_checklists/1
# DELETE /org_checklists/1.json
def destroy
@org_checklist.destroy
respond_to do |format|
format.html { redirect_to org_checklists_url, notice: 'Org checklist was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_org_checklist
@org_checklist = OrgChecklist.find(params[:id])
authorize @org_checklist
end
# Never trust parameters from the scary internet, only allow the white list through.
def org_checklist_params
params[:org_checklist].permit(:organisation_id, :payment_method, :interests_set )
end
end
谁能看出问题所在?
【问题讨论】:
标签: ruby-on-rails path controller