I'm trying to get more into the Ruby mindset. I know I should accomplish
more with less code. I came up with this method that does work, but I
think could really use some simplification.
There is 4 models.
Company (belongs to Account)
(belongs to Company)
(belongs to Role)
(to get the account id, I would need to do user.company.account_id)
User.role_id (if it's a 1, it means it's the Account Owner)
There is only ONE account owner per account.
So, when a "customer"(role_id=4) signs in, under the Users tab, he's
supposed to see two companies:
1) the company he belongs to
2) and the account owners company
So I need to come up with something like this:
@companies = Company.all(:conditions => ["id == ? or id == ?",
1) Coming up with the company he belongs to it's easy:
2) Coming up with the account owner company id it's more difficult and
requires several queries. The method I have does the following:
a) Finds the customer's account_id
b) Looks for ALL account owners in the database
c) Tries to match the customer's account_id to one of the account
d) Finally, returns the account owner's company id