在Rails App中向索引方法显示简单消息

时间:2014-05-30 14:39:03

标签: ruby-on-rails-4

我需要在显示索引页面时添加警告消息/通知。 我怎样才能做到这一点 ? 我目前的索引方法是:

  def index
   @routes = Route.all
  end

1 个答案:

答案 0 :(得分:0)

在您的控制器上

def index
  @routes = Route.all
  flash[:notice] = "text for the warning message / a notice"
end

并在视图上

- flash.each do |val|
  =val