'ID' でプロジェクトを見つけることができませんでした:ruby-は、私は以下のように、このネストされたリソースのエラーだ=
のActiveRecord ::のRecordNotFoundを管理/プロジェクト/ 2/project_comments /で
プロジェクトが見つかりませんでした'ID' =
routes.rbを
namespace :admin do
resources :users
resources :projects do
resources :project_users
resources :project_comments
end
end
project.rb
has_many :project_comments
と
project_comment.rn
belongs_to :project
project_comments_co
class Admin::ProjectCommentsController < ApplicationController
before_action :set_project_comment, only: [:show, :edit, :update, :destroy]
before_action :set_project
def your_action
# these are for debugging
puts params.inspect
puts params[:option_id]
@event = Event.find(params[:event_id])
@option = Option.find(params[:option_id])
end
def index
@project_comments = @project.project_comments.all
end
def new
@project_comment = @project.project_comments.new
end
def create
@project_comment = @project.project_comments.new(project_comment_params)
if @project_comment.save
else
end
end
def show
end
def edit
end
def update
if @project_comment.update(project_comment_params)
else
end
end
def destroy
@project_comment.destroy
end
private
def set_project
@project = Project.find(params[:id])
end
def set_project_comment
@set_project_comment = ProjectComment.find(params[:id])
end
def project_comment_params
params.require(:project_comment).permit(:project_id, :user_id, :comment)
end
エンド
は私を助けてくれてありがとう!
あなたのset_projectメソッドでは、params [:id]はparams [:project_id]である必要があります。 – Deep
ありがとうございました!私は今それを解決しました – JiaPing