Supporting two kinds of user profiles I have fully working code, however I'd like to make it nice. I've got these three models:


  
  User (can have both or either one)
  user can have one trucker
  user can have one owner_trucker
  Trucker
  belongs to user
  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 locally.

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? &amp;&amp; current_user.owner_trucker.nil?


It this refactorable?
I think your suspicion that the code is a "wet" is correct.  I would start moving these predicates into the model whenever they are:


Used more than once, or
Can make the code clearer by having a named predicate.


Consider replacing this:

helper_method :profile_type_from_user
  def profile_type_from_user(user)
    return profile = user.trucker ? :trucker : :owner_trucker
  end


With this:

class User
  ...
  def profile_type
    trucker ? :trucker : :owner_trucker
  end
  ...
end


Similarly, consider replacing this:

@profile = current_user.trucker ? current_user.trucker : current_user.owner_trucker


with:

class User
  ...
  def profile
    trucker || owner_trucker
  end
  ...
end

@profile = current_user.profile