I have my attend method below currently in my controller. My question is how do I know whether to put this in my event or user model vs. my events controller? I am also going to add another method remove_attend which will do the opposite of attend. At what point do I put these methods into a model?
def attend
@event = Event.find(params[:id])
if @event.users.include?(current_user)
flash[:error] = "You're already attending this event."
else
current_user.events << @event
flash[:success] = "Attending event!"
end
redirect_to @event
end
It belongs to the event controller. Flash messages or redirects cannot be put in the models. So, when you see either, it’s safe to assume that they are controller material.
It belongs to the event controller because the resource that attend refers to is an Event. You can create, edit or attend an event, in that sense.