The user can comment on the screen and track it at the address of PublicActivity:
@comment.create_activity :create, owner: current_user, recipient: @comment.screen.user
and comments depend on :: destroy on the screen.
But when I delete the screen and the comments are deleted, the entry from PublicActivity for this comment still exists.
here is my Screens Controller :
def destroy @activity = PublicActivity::Activity.find_by_trackable_id(params[:id]) @activity.destroy
But when I delete the screen, I get an undefined method destroy 'for nil: NilClass`.
I read in Railscast:
this is called by calling the create_activity method after the object has been destroyed.
According to the custodians of the gemstones, you just need to take the record will be destroyed and will cause create_activity before destruction
What am I missing?
Info 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
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
What my Destroy Action screen controller looks like right now:
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
Again the same error:
