This is a fairly simple question.
Is there a specific method for updating properties for relationships in the gem? I can't seem to do a simple update_attributes or update.
My relationship is created and update is undefined for nil class.
event = Event.find(params[:event])
invite = Invite.create_invitation(event, current_user, nil) #creates relationship
invite.update(interested: params[:interest])
Is there another method that I should be using?
Whenever you get an error about undefined for nil class, it should be an immediate signal to you that the problem is the variable on which you're calling the method, not the method you're calling. In other words, since it's saying that
nildoes not have anupdatemethod, your focus should be on the variable that is actually nil. The question here: why isinvitereturningnilinstead of a relationship?Since you're using a custom class method to create the relationship, I'm guessing that you're not telling it to return the right object. It should look something like this:
Then your controller needs to check that the rel was actually created correctly.
This feels to me like you're taking a long way around this problem. You don't need to separate the creation of the relationship and setting the
interestedproperty, you can just do it in one call to the DB:Since you know you're always going to create that
interestedproperty, this looks like a good place to add a validation to your model to ensure that the property is always set on create.