I have fully working code, however I'd like to make it nice. I've got these three models:
1. User(can have both or either one)
user can have one trucker
user can have one owner_trucker
2. Trucker
belongs to user
3. OwnerTrucker
belongs to user
I'm not the only one working in the app, but it starts to annoy me how everyone is solving the issue on its way.
The problem is how to determine what the user is (a trucker
or a owner_trucker
or both). i.e if user.trucker
is not nil, its a trucker
etc.
So here are few examples from the application (various controllers), basically checking for the same thing but in a different way:
helper_method :profile_type_from_user
def profile_type_from_user(user)
return profile = user.trucker ? :trucker : :owner_trucker
end
And then used in another controller like:
if profile_type_from_user(profile) == :trucker
else
end
Another example would be:
@profile = current_user.trucker ? current_user.trucker : current_user.owner_trucker
Checking if one or another:
current_user.trucker? && current_user.owner_trucker.nil?
It this refactorable?
owner_truckers
also a type oftrucker
? How is auser
who is anowner_trucker
different than if they were both atrucker
and anowner_trucker
? As it is seems like there are opportunities to remove these checks (or at least express them more meaningfully as part of theUser
) but without more understanding of the domain it's not clear what would be valid. – Jonah Jan 15 at 3:13