I am trying to implement a feature of join event and cancel event. I have already created attendances table and include status as attribute. The relation is many to many to so in my attendance model code looks like this
class Attendance < ApplicationRecord belongs_to :attendee, class_name: "User", foreign_key: "attendee_id" belongs_to :attended_activity, class_name: "Activity", foreign_key: "attended_activity_id" enum status: { joined: 0, canceled: 1 }end
how I am showing it in show view page
<% if current_user.attending?(@activitie, status: "joined") %><%= button_to "Leave Event", activity_attendance_path(@activitie), method: :delete, class: "btn btn-danger" %><% else %><%= button_to "Attend", activity_attendances_path(@activitie), method: :post, class: "btn btn-success" %><% end %>The attending method
def attending?(activity, status: "joined")attendances.exists?(attended_activities: activity, status: status)end
I guess it is throwing error in the attending method but when I used byebug and called attedances I keep getting ArgumentError (wrong number of arguments (given 0, expected 1..2)): indicating enum which is in attendance model