I'm trying to perform a check on my User model using a series of nested if statements. I have two models, User, which has_many :taxes
, and tax which belongs_to :user
. Within a column of the user table, each user has a specific "state id" which they select when they sign up (for example, state_id: 53
could mean California). Anyway, in my Tax model, I have several if
statements which evaluate to see if a user is from a specific region, and if true, the conditions inside the if are performed.
For example:
if user_state_id == 53
# Do this
end
The problem is, if the user isn't a match to the first if statement, it doesn't continue to check the remaining statements to see if it matches any of the others. (See Below). If this user had a state_id
of 53, it would work normally and run the remaining conditions inside. However, if the user had a state_id
of 52 (next in the list) it would not evaluate.
def provincial
if user.state_id == 53 #BC
if calculation = self.income <= 10276
return 0
elsif calculation = self.income > 10276 && self.income <= 37568
return self.income * 0.0506
end
end
if user.state_id == 52 #AB
if calculation = self.income <= 17593
return 0
elsif calculation = self.income < 17593
return self.income * 0.10
end
end
if user.state_id == 60 #ON
if calculation = self.income <= 9574
return 0
elsif calculation = self.income > 9574 && self.income <= 39723
return self.income * 0.0505
end
end
end
I also tried using elsif
statements for the primary nested condition checks (elsif user.state_id == 52...
) but that did not work either.