Rails - flash [:alerts]没有显示

时间:2016-02-25 14:23:10

标签: ruby-on-rails ruby alert

我想打印一条简单的消息作为提醒,就像用户写下他的电子邮件点击订阅按钮一样。

Your email is saved, you'll be contacted for a beta very soon!

这是我的观点:

<form action="/welcome/subscribe" date-remote="true">
    <div>
        <div id="bottomm">
            <input id="bottom" type="text" name="email" placeholder="email" />
        </div>
        <div>
            <input type="submit" value="Ok" class="fit" />
        </div>
        <%= alert %>
    </div>
</form>

这是我控制器中的订阅方法:

def subscribe
    @test = Test.new
    @test.email = params['email']
    @test.save
    redirect_to root_url, notice: "Your email is saved, you'll be contacted for a beta very soon!"
end

但没有任何表现。我看到一些人在堆栈上遇到了与我相同的问题,但我尝试了解决方案但是没有用。

我试过这些,但没有一个对我有用。

flash.keep
flash[:notice] = "..."
flash.now[:notice] = "..."
flash[:alert] = "..."
flash.now[:alert] = "..."
and redirecting after

1 个答案:

答案 0 :(得分:2)

你是否在application.html.erb或你的根视图中有一个块来实际显示闪光灯,如下所示:

<% if notice.present? %>
   <p><%= notice %></p>
<% end %>

如果没有,那可能就是问题所在。

相关问题