0

我在 rails 3 项目中使用 twitter 引导程序,并且无法在成功创建帖子时显示 Flash 消息。

这是代码 - 你能告诉我我做错了什么吗?

谢谢,

费萨尔


帖子控制器

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 视图

<!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>
4

1 回答 1

0

确保您的视图中有这样的内容(例如views/application.html.erb)

 <% flash.each do |name, msg| %>
    <%= content_tag :div, msg, :id => "flash_#{name}" %>
 <% end %>
于 2012-05-16T19:34:48.760 回答