ruby-on-rails - 如果用户登录? CASE current_user.plan_id 否则...?

标签 ruby-on-rails case erb

这个用于显示用户/成员状态的“优雅”助手在案例 1-3 中工作完美,但不工作(在 ERB View <%= user_cat %> 中不显示任何内容)用于:

  • user.plan_id=NULL

错误是什么?如何解决?


  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 和 Rails 6.0.0

提前致谢!

最佳答案

谢谢!

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

关于ruby-on-rails - 如果用户登录? CASE current_user.plan_id 否则...?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58455614/

相关文章:

ruby-on-rails - Rails 3 : How to stop logger from logging/healthcheck requests?

ruby-on-rails - Ruby on Rails Controller WHERE 语句

sql - Rails 迁移在另一个表中创建条目时更新现有记录

ruby - 如何在 "case when"中捕获 Errno::ECONNRESET 类?

ruby-on-rails - 没有 rails 的 ERB 中的 yield

ruby-on-rails - Rspec-view-file 不知道我的路线

mysql - SQL Shortel 放弃调用查询

ruby 字符串匹配忽略大小写

ruby-on-rails - 在 Rails 中的 ERB 中实现 if/not 的最干净的方法是什么?

javascript - 在实现 toast 中设计通知/警报的简洁方法