IF user_signed in? CASE current_user.plan_id ELSE ...?

Viewed 41

This 'elegant' helper for showing the user/member status is working perfectly for CASE 1-3 but not working (not showing anything at ERB view <%= user_cat %>) for:

  • user.plan_id=NULL

What's the error? How to fix it?


  def user_cat
    if user_signed_in?
      case current_user.plan_id
      when 1 
        'ESPORÀDIC'
      when 2 
        'FREQÜENT'
      when 3 
        'HABITUAL'
      end 
    else
      'IDENTIFICA\'T'
    end
 end

Ruby 2.64 and Rails 6.0.0

Thanks in advance!

1 Answers

Thanks!

def user_cat
    if user_signed_in?
      case current_user.plan_id
      when 1 
        'ESPORÀDIC'
      when 2 
        'FREQÜENT'
      when 3 
        'HABITUAL'
      else
        'SUBCRIUTA\'T' 
      end 
     else
      'IDENTIFICA\'T'
    end
  end
Related