当前位置: 动力学知识库 > 问答 > 编程问答 >

ruby on rails - Why I see '0' when I use current_user.has_role?

问题描述:

In view I set validation for roles (gems cancan and rolify).

As example in HAML

=if current_user.has_role? :admin

= link_to current_user.name, '#'

Generated HTML

<a href="#">Administrator</a>

"

"

Why I see '0'?

网友答案:

You should use a - in front of your if statement, probably:

- if current_user.has_role? :admin
  = link_to current_user.name, '#' 

When you use an = there, it's going to display the result of that expression, which is not what you want.

分享给朋友:
您可能感兴趣的文章:
随机阅读: