先看一下model中的代码 USERTYPE = [[ " 普通学员 " , 0 ],[ " 讲师 " , 1 ],[ " 系统管理员 " , 2 ]] 数据库中存的通常是0,1,2但我们却需要显示中文,比如说普通会员,讲师,系统管理员。一般我们的做法是 <% ... '普通会员' if @user.usertype == '0'%><% '讲师' if @user.usertype == '1'%><% '系统管理员' if @user.usertype == '2'%> 但这样太不灵活了!现在好了,看下面代码 <% = AlaUser::USERTYPE.rassoc(@user.usertype.to_i)[ 0 ] %>