사용자의 화면에 대해 언급 할 수 있으며이 PublicActivity 추적 있어요에 '파괴 :정의되지 않은 방법은`공개 활동
@comment.create_activity :create, owner: current_user, recipient: @comment.screen.user
및 코멘트 의존 : 화면 모델을 파괴한다.
그러나 화면을 삭제할 때 주석이 삭제되는 동안 해당 주석에 대한 PublicActivity의 레코드는 계속 존재합니다.
def destroy
@activity = PublicActivity::Activity.find_by_trackable_id(params[:id])
@activity.destroy #<-- Heres the Problem
@screen.destroy
respond_to do |format|
format.html { redirect_to root_path }
format.json { head :no_content }
end
end
그러나 화면 삭제시
, 내가undefined method
이 전무에 대한 '파괴 받고 있어요 : NilClass`
여기 내 Screens Controller
입니다.
it was due to calling the create_activity method after the object had been destroyed.
According to the gem maintainers, you simply have to assume the record will be destroyed, and call create_activity before the destroy
내가 무엇을 놓치고?
Informations below
screen.rb
belongs_to :user
has_many :comments, :dependent => :destroy
comment.rb
belongs_to :user
belongs_to :screen
screens_contoller.rb
def create
@screen = current_user.screens.build(screen_params)
respond_to do |format|
if @screen.save
format.html { redirect_to @screen, notice: 'You successfully uploaded your Screenshot.' }
format.json { render action: 'show', status: :created, location: @screen }
current_user.add_points(2, 'Points for Uploading a Screenshot')
else
format.html { render action: 'new' }
format.json { render json: @screen.errors, status: :unprocessable_entity }
end
end
end
def destroy
@activity = PublicActivity::Activity.find_by_trackable_id(params[:id])
@activity.destroy
@screen.destroy
respond_to do |format|
format.html { redirect_to root_path }
format.json { head :no_content }
current_user.substract_points(1, "Substraction for Deleting a Screenshot")
end
end
comments_controller.rb
,174 내 스크린 컨트롤러 액션을 파괴하는 방법은def create
@screen = Screen.find(params[:screen_id])
@comment = current_user.comments.build(comment_params)
@comment.screen_id = @screen.id
respond_to do |format|
if @comment.save
# Create Record for Public Activity
@comment.create_activity :create, owner: current_user, recipient: @comment.screen.user
format.html { redirect_to @screen, notice: 'Comment was successfully created.' }
format.json { render action: 'show', status: :created, location: @comment }
else
format.html { render action: 'new' }
format.json { render json: @comment.errors, status: :unprocessable_entity }
end
end
end
def destroy
@comment.destroy
respond_to do |format|
@activity = PublicActivity::Activity.find_by_trackable_id(params[:id])
@activity.destroy
format.html { redirect_to :back }
format.json { head :no_content }
end
end
지금과 같습니다이
def destroy
@screen = current_user.screens.find(params[:id])
@activity = PublicActivity::Activity.find_by_trackable_id(params[:id])
@activity.destroy
@screen.destroy
current_user.substract_points(1, "Substraction for Deleting a Screenshot")
respond_to do |format|
format.html { redirect_to root_path }
end
end
다시 같은 오류 :이 테스트되지 않은 상태입니다
여기서'@ screen'을 가져옵니다. 그의 객체는 무제한 객체이고 그 객체를 파괴하려고합니다. –
'@screen = Screen.find (params [: id])?당신이 바닥에 set_screen에 그것을 가지고 있지 않는 한. 하지만 분명히 변수'@ screen'을 어디에도 만들지는 않습니다. –
@MohamedElMahallawy Set_screen에 있습니다. 내 질문 편집 –