我得到這個嵌套資源錯誤象下面這樣:ruby-無法與 'ID' 找項目=
的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