我在rails 3项目中使用了twitter bootstrap,并且在成功创建帖子时无法显示flash消息。
这是代码 - 你能让我知道我做错了吗?
谢谢,
费萨尔
POSTS CONTROLLER
def create
@post = Post.new(params[:post])
@post.user = current_user
respond_to do |format|
if verify_recaptcha && @post.save
format.html { redirect_to '/home'}
format.json { render :json => @post, :status => :created, :location => @post }
flash[:notice] = "Thank you, your request has been submitted."
else
format.html { render :action => "new" }
format.json { render :json => @post.errors, :status => :unprocessable_entity }
end
end
end
APPLICATION.HTML.ERB VIEW
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>The little chits that ended 3 years of unemployment for me.</title>
<%= csrf_meta_tags %>
<%= stylesheet_link_tag "application", :media => 'all' %>
<link href="images/favicon.ico" rel="shortcut icon">
<link href="images/apple-touch-icon.png" rel="apple-touch-icon">
<link href="images/apple-touch-icon-72x72.png" rel="apple-touch-icon" sizes="72x72">
<link href="images/apple-touch-icon-114x114.png" rel="apple-touch-icon" sizes="114x114">
</head>
<body>
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="btn btn-navbar" data-target=".nav-collapse" data-toggle="collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="brand" href="/home">LittleChits</a>
<div class="container nav-collapse">
<ul class="nav">
<li><%= link_to "Home", "/home" %></li>
<li><%= link_to "How it Works", "/howitworks" %></li>
<li><%= link_to "About Us", "/thestory" %></li>
<li><%= link_to "Plans & Pricing", "/posts/new" %></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
</div>
<div class="container">
<div class="content">
<div class="row">
<% flash.each do |name, msg| %>
<%= content_tag :div, msg, :id => "flash_#{name}" %>
<% end %>
<%= yield %>
</div><!--/row-->
</div><!--/content-->
</div> <!-- /container -->
<!-- Le javascript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<%= javascript_include_tag "application" %>
</body>
</html>
答案 0 :(得分:0)
确保您的视图中包含类似内容(例如views / application.html.erb)
<% flash.each do |name, msg| %>
<%= content_tag :div, msg, :id => "flash_#{name}" %>
<% end %>