css - Rails - 如何将 css 添加到辅助方法

标签 css ruby-on-rails helper view-helpers

我试图将一个很长的 if 语句从我的 View 中移出并放入辅助方法中。

我目前有:

module ProfilesHelper
    def items_for_profile_menu(profile)
        if current_user = @profile.user_id 
      "<li class="col-xs-4 col-sm-2 nopadding menuitem" style="background:#006F7F">
               <a href="index.html" class="hvr-sweep-to-bottom">
                       # link_to dashboard_path(@profile.dashboard) 
                      <span>Dashboard</span>
               </a>

        </li>

                <li class="col-xs-4 col-sm-2 nopadding menuitem" style="background:#39AFBF">
                     <a href="#resume" class="hvr-sweep-to-bottom">
                     <!-- <i class="flaticon-graduation61"></i> --><br><br>
                     <span>Timeline</span></a>
        </li>"

    <% else %>

                  "<li class="col-xs-6 col-sm-3 nopadding menuitem orange">
                     <a href="#stats" class="hvr-sweep-to-bottom"><i class="flaticon-placeholders4"></i><span>Impact</span></a>
                  </li>
                  <li class="col-xs-6 col-sm-3 nopadding menuitem red">
                     <a href="#feedback" class="hvr-sweep-to-bottom"><i class="flaticon-earphones18"></i><span>Feedback</span></a>
                  </li>"
               <% end %>

    end


end

我不知道是否可以在助手本身中编写 css?如果可以,我如何才能了解使其正常工作所需的修改?在 View 中,我能够在列表项中写入:background:#006F7F。如果我将其添加到帮助程序 - 那么 # 将作为评论收到。

谁能看到如何使用 CSS 设置辅助方法?

最佳答案

例如使用.html_safe:

def my_name
    name = "<h1>Eric Santos!</h1>"
    name.html_safe
 end

希望你明白了!

关于css - Rails - 如何将 css 添加到辅助方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38690973/

相关文章:

css - 字体 url 在 angular 5 css 引用中不起作用

html - Bootstrap 4 卡图像不对齐

ruby-on-rails - 如何在erb中编写while循环

html - 嵌套的 div 导致 bootstrap3 中的内联元素?

html - 固定位置不适用于标题

mysql - 将数据从 excel 表存储到 ror 中的 db

ruby-on-rails - 在 Rails 3 中强制 "humanized"字段名称为小写

asp.net - 使用 t4 从另一个程序集读取 web.config

ember.js - Emberjs 模板中的增量

jquery - 如何在页面加载前加载 load jquery