轨道通知不出现 [英] rails notices not appearing

查看:244
本文介绍了轨道通知不出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在使用Bootstrap的Rails 4中

$ p> def创建
@contest = Contest.new(contest_params)
如果@ contest.save
flash [:notice] =比赛已成功保存
redirect_to @contest
else
redirect_to root_path,:notice => '未保存的项目'
结束
结束

怎么没有通知当我提交表格?有什么我失踪?我是初学者,一直没能弄清楚。



我的布局中已经有了以下内容:

 <体> 
< p class =notice><%= flash [:notice]%>< / p>
< p class =alert><%= flash [:alert]%>< / p>

<%= render'layouts / header'%>

<%= yield%>

<%= render'layouts / footer'%>

< / body>


解决方案

  flash [:notice] ='项目保存成功'
redirect_to about_path
解决方法如果您想尝试:

  redirect_to url,:flash => {:notice => notice} 

同时编辑布局




$ b

删除布局标头,以免发生冲突。

 < body> 
< p class =notice><%= flash [:notice]%>< / p>
< p class =alert><%= flash [:alert]%>< / p>

<%= yield%>

<%= render'layouts / footer'%>

< / body>


I'm in Rails 4 using Bootstrap

This is my create action in my controller:

  def create
    @contest = Contest.new(contest_params) 
    if @contest.save
      flash[:notice] = "Contest saved successfully"
        redirect_to @contest
    else
        redirect_to root_path, :notice => 'Project not saved'
    end
  end

How come there is no notice when I submit the form? Is there something I am missing? I'm a beginner and have not been able to figure this out.

I have the following in my layout already:

  <body>
    <p class="notice"><%= flash[:notice] %></p>
      <p class="alert"><%= flash[:alert] %></p>

    <%= render 'layouts/header' %>

      <%= yield %>

    <%= render 'layouts/footer' %>

  </body>

解决方案

try like this:

 flash[:notice] = 'Project saved successfully'
 redirect_to about_path

redirect with flash was broken in some versions. Workaround if you want to try:

redirect_to url, :flash => { :notice => "notice" }

also edit your layout

Remove the layouts header in case it conflicts.

 <body>
     <p class="notice"><%= flash[:notice] %></p>
      <p class="alert"><%= flash[:alert] %></p>

      <%= yield %>

    <%= render 'layouts/footer' %>

  </body>

这篇关于轨道通知不出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆