title: using nested case statements to return value
body: <p>I'm trying to use case statements to have a value returned, depending on the conditions. Unfortunately I'm getting a string of syntax errors because I'm not completely familiar with how a case statement should be set up.</p>
  
  <p>Basically, a user can belong to a single state (region), so in the user table is where the user's "state_id" is stored (53 could be Oregon for example). I had most of this working using if statements, but it was far too messy, so I was told "case" would be the better way to go. I also have a model "tax" which belongs_to a user and a user can have many of.</p>
  
  <p>Prior to changing to using case, I was doing <code>if user.state_id == 53</code> for example, which was working, and then the conditions were <code>if self.income &lt;= 10276</code> which also worked. Now with the case however, although slightly more refactored, I can't get it working.. (many syntax errors due to the evaluators <code>&lt;=</code> and all the others.)</p>
  
  <pre><code>def provincial
  case user.state_id
  when 53
      case income
        when &lt;= 10276
          return 0
        when 10277..37568
          return self.income * 0.0506
        when 37569..75138
          return ((self.income - 37568) * 0.077) + 1901
        when 75139..86268
          return ((self.income - 75138) * 0.105) + 4794
        when 86269..104754
          return ((self.income - 86268) * 0.1229) + 5963
        when &gt; 104754
          return ((self.income - 104754) * 0.147) + 8235
      end
  
  when 52
      case income
        when &lt;= 17593
          return 0
        when &gt; 17593
          return self.income * 0.10
      end
  end
  end
  </code></pre>