In my Rails 5 app, I'm using the Public_Activity gem and I'm trying to record an activity, but running into an error: ArgumentError (wrong number of arguments (1 for 0).
I tried to record the activity in my controller, but I was having trouble because I couldn't figure out how to specify my model instance (CanvasProduct
). So I tried to create the entry in the model using what I found in the documentation.
my controller (creates a CanvasProduct
):
def add_product
product = Product.friendly.find(params[:product_id])
if @canvas.canvas_products.create product: product
render nothing: true, status: :created
else
render nothing: true, status: :bad_request
end
end
My model
class CanvasProduct < ActiveRecord::Base
belongs_to :canvas
belongs_to :product
include PublicActivity::Common
after_create :create_activity
def create_activity
@cp = self
@cp.create_activity :create, recipient: @cp.canvas
end
end