【问题标题】:method in application_helper is not workingapplication_helper 中的方法不起作用
【发布时间】:2014-12-19 19:47:01
【问题描述】:

我正在使用twitter-bootstrap 进行设计。这是我的layouts/application.html.erb 文件:

  <% flash.each do |type, message| %>
      <div class=" <%= flash_class type %> " >
        <button type="button" class="close" data-dismiss="alert">&times;</button>
        <%= message %>
      </div>
  <% end %>

helpers/application_helper.rb 文件:

module ApplicationHelper
  def flash_class(type)
    case type
    when :alert
        "alert alert-error"
    when :notice
        "alert alert-success"
    else
        "alert"
    end
  end
end

我的flash_class 方法无法正常工作。每次只调用else 选项。不知道为什么?如果您需要更多信息,请发表评论。

【问题讨论】:

    标签: ruby-on-rails ruby twitter-bootstrap ruby-on-rails-4


    【解决方案1】:

    我怀疑flash给出的type是一个字符串。您是否尝试使用字符串而不是符号进行比较?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多