2012-05-16 112 views
0

我在rails 3項目中使用twitter bootstrap,並且無法在創建成功後顯示Flash消息。未顯示Flash成功消息

這裏是代碼 - 你能讓我知道我在做什麼錯嗎?

感謝,

費薩爾


Posts控制器

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

確保類似這樣的東西在您的視野中(例如views/application.html.erb)

<% flash.each do |name, msg| %> 
    <%= content_tag :div, msg, :id => "flash_#{name}" %> 
<% end %> 
+0

試過了,沒有工作...見上面的application.html.erb代碼。 (閃存代碼被截斷到最後) – hikmatyar