css - 有条件的显示栏杆

标签 css ruby-on-rails ruby

我试图仅在当前用户是“主持人”时显示删除按钮,但即使主持人的用户 ID 与 guest 的用户 ID 匹配,该按钮也是隐藏的

<%= link_to "X" , "/songs?name=#{s.name}&party_profile_id=#{s.party_profile_id}&commit=X", :remote => true, :class => "btn btn-inverse btn-small refreshbutton", :style => "display:none" unless @current_user.id == @party_profile.host %>

我是否使用了错误的语法?是否有更好的方法来有条件地显示元素?

最佳答案

您可以切换为只渲染它,而不是切换 css 类(除非您的应用程序出于某种原因需要在客户端切换它)。

<% if @current_user.id == @party_profile.host %>
    <%= link_to "X" , "/songs?name=#{s.name}&party_profile_id=#{s.party_profile_id}&commit=X", :remote => true %>
<% end %>

关于css - 有条件的显示栏杆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14945351/

相关文章:

html - 如何删除 Bootstrap div 之间的空间

html - 如何在 Code Runner 中使用 css

ruby-on-rails - Rails Controller 是多线程的吗? Thread.exclusive 在 Controller 中

ruby-on-rails - rails 命名空间助手隔离

ruby - 为什么 `method=` 没有像其他任何方法一样对待?

ruby - 在 Jekyll 中读取文件时出错

ruby-on-rails - Rails - 参数丢失或值为空 : measure

javascript - Bootstrap 无法在管理模板下运行

html - 如何使用 CSS 在 div 中选择带有文本的跨度?

jquery - 仅启用当前日期直至 future 30 天 - bootstrap datepicker