[英]The flash notice message is not displaying “ ruby on rails”
I searched for an answer before I came here but found nothing. 我来这里之前一直在寻找答案,但一无所获。 I have this in my controller
我的控制器中有这个
def create
@article = Article.new(article_params)
if @article.save
flash[:notice] = "Article was successfully created"
redirect_to article_path(@article)
else
render 'new'
end
end
and I add this in my application.html.erb: 并将其添加到我的application.html.erb中:
<body>
<% flash.each do |name, msg| %>
<ul>
<li><%= msg %></li>
</ul>
<% end %>
<%= yield %>
and here is my show.html.erb: 这是我的show.html.erb:
<h1>Showing selected article</h1>
<p>
Title: <%= @article.title %>
</p>
<p>
Description: <%= @article.description %>
</p>
After submitting the form I go to the show page,the flash notice does not display. 提交表格后,我进入显示页面,闪动通知不显示。 why?
为什么?
I have look into your github repo, it seems that you are not using application.html.erb as your layout, because your article controller is inherited from ActionController::Base
我查看了您的github存储库,看来您没有使用application.html.erb作为布局,因为您的文章控制器是从
ActionController::Base
继承的
There are 2 ways you can do this. 您可以通过2种方法执行此操作。
You can either change your controller file to inherit from ApplicationController: 您可以更改控制器文件以继承自ApplicationController:
class ArticlesController < ApplicationController
end
Or you can add default layout to the controller file: 或者,您可以将默认布局添加到控制器文件:
class ArticlesController < ActionController::Base
layout 'application'
end
Hope it solves your problem. 希望它能解决您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.