I generated a scaffold using the rails generator, and created the controller below.
When I try to check if it works, I get an error message that says:
ActiveRecord::RecordNotFound at /org_checklists/index
Couldn't find OrgChecklist with 'id'=index
I was getting the same error recently (question below) and the solution was to remove :index
from the before action
. However, this controller doesn't include that action in the 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
Can anyone see what's wrong?