두 개의 컨트롤러와 모델 Projects
및 Schemas
이 있습니다. Schemas
belongs_to
프로젝트. Projects
has_many
schemas
. http://localhost:3000/projects/SLUG-PROJECT/schemas/SLUG-SCHEMA을 찾고 있습니다. 이건 내 코드입니다일치하는 경로가 없습니다 ... 필수 키가 누락되었습니다
class Projects::SchemasController < ApplicationController
before_action :set_schema, only: [:show, :edit, :update, :destroy]
before_action :set_project, only: [:index, :show, :new, :edit, :update, :destroy]
def index
@schemas = Schema.all
end
def show
end
def new
@schema = Schema.new
end
def edit
end
def create
@schema = Schema.new(schema_params)
respond_to do |format|
if @schema.save
format.html { redirect_to project_url(@schema.project_id), notice: 'Schema was successfully created.' }
else
format.html { render :new }
end
end
end
def update
respond_to do |format|
if @schema.update(schema_params)
format.html { redirect_to project_url(@schema.project_id), notice: 'Schema was successfully updated.' }
else
format.html { render :edit }
end
end
end
def destroy
@schema.destroy
respond_to do |format|
format.html { redirect_to project_url(@schema.project_id), notice: 'Schema was successfully destroyed.' }
end
end
private
def set_schema
@schema = Schema.find(params[:id])
end
def set_project
@project = Project.friendly.find(params[:project_id])
end
def schema_params
params.require(:schema).permit(:number, :identification, :reference, :name, :description, :author, :controller, :priority, :notes, :status, :cycle, :slug, :project_id)
end
end
:
다음은 내 SchemaController
코드입니다 그것은 지수와 쇼 페이지에 대한 작동
respond_to do |format|
if @schema.update(schema_params)
format.html { redirect_to project_url(@schema.project_id), notice: 'Schema was successfully updated.' }
else
format.html { render :edit }
end
,하지만 난 갱신, 편집을위한 다음과 같은 오류가 발생, 파괴 :
ActionController::UrlGenerationError in Projects::SchemasController#update
No route matches {:action=>"show", :controller=>"projects", :id=>nil} missing required keys: [:id]
아무도 내가 무슨 일이 일어나는지 알아낼 수 있습니까?
당신이 당신의 설정/routes.rb를 공유 안될까요? – dskecse