Here's the error I get:
ActionView::Template::Error (You have a nil object when you didn't expect it!
You might have expected an instance of Array.
It's referring to this code in a view partial:
<% flash.each do |key, value| %>
<div class="<%= key %>"><%= value %></div>
<% end %>
I set the flash message in my micropost controller:
def create
@micropost = current_user.microposts.build(params[:micropost])
respond_to do |format|
if @micropost.save
flash[:success] = "Micropost created!"
format.html { redirect_to root_path, :notice => 'success' }
format.js
Here's my js code in views/microposts/create.js.erb:
$('div.notice').append('<%= render 'shared/flash' %>');
And the partial gets rendered dynamically in my application layout:
<body>
<div class="container">
<%= render 'layouts/header' %>
<section class="round">
<div id= "notice"></div>
<%= yield %>
</section>
<%= render 'layouts/footer' %>
<%= debug(params) if Rails.env.development? %>
</div>
</body>
How do I fix this error? What am I doing wrong?