问题
DHH wrote an article advocating for the use of concerns. It seems like a good practice, and in a lot of cases, they work well with my app. There are several cases, however, where multiple models have similar but slightly different methods, such as:
def find_or_create_membership
user_membership = User::Membership.where(:group_id => self.group_id,
:user_id => self.invitee_id).first_or_create(:status => "invited")
end
and:
def find_or_create_membership
user_membership = User::Membership.where(:group_id => self.group_id,
:user_id => self.invitee_id).first_or_create(:status => "declined")
end
These methods are identical save that the first sets status
to "invited" and the second to "declined". Is there a way I could pass an argument to these methods via a concern?
回答1:
You might be interested in Paramix.
Never used it myself, though. Dunno, smells like a False-Good-Idea©.
来源:https://stackoverflow.com/questions/15529079/rails-passing-an-argument-to-a-concern