views:

28

answers:

2

I have a Members ActiveRecord model and I want to create a method that would fetch members from an external source and synchronize them with the members in the database already.

I don't know where I should put that method that would be called. It seems like I shouldn't put it in the controller since it is a lot of logic, but I don't know if I can add it to the model since that seems to operate on the row only.

Any advice would be appreciated, I am new with RoR

A: 

Based only on the information you've given, I'd make it a class method for the model: def self.get_externals. That way you'd call it like Member.get_externals, and it wouldn't seem to be operating upon a single row like you're worried about.

Twisol
A: 

If in doubt, stick it in lib.

Pulling from the network does not seem like it belongs in the model.

cwninja
Well, he wants to synchronize against the pulled-in members, so it seems like something that would logically go in the model.
Twisol
But is is not a model. With good design, it should be able to act just as easily on another model. It feels to me like the functionality should be acting on the two collections (one remote, one in the database (or the other way round)), so it should not be a member of either.
cwninja
It would be fairly easy to move this sort of function to a lib at some point, in my opinion. If he's only using it for one Model, and if it's unlikely that he'll be using it for other Models in the future, it doesn't do any harm to make it a class method.
Twisol