Rails新模型Ajax响应

I'm trying to make a simple example on a new form to send the notice of success when creating a new item using ajax. I'm reciving a response from the server with 500 internal error.

new.js.erb

$("#flash-messages").html("<%= notice %>")

new.html.erb

<h1>New Ajax</h1>

<%= form_for(@ajax, remote: true) do |f| %>
<div id="flash-messages" >
</div>
<% if @ajax.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@ajax.errors.count, "error") %> prohibited this ajax from being saved:</h2>

  <ul>
  <% @ajax.errors.full_messages.each do |message| %>
    <li><%= message %></li>
  <% end %>
  </ul>
</div>
  <% end %>

<div class="field">
<%= f.label :name %><br>
<%= f.text_field :name %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>

controller

  def create
  @ajax = Ajax.new(ajax_params)

respond_to do |format|
  if @ajax.save
    format.html { redirect_to @ajax, notice: 'Ajax was successfully created.' }
    format.json { render :show, status: :created, location: @ajax }
    format.js { redirect_to new_ajax_path, flash[:notice] = "Fudeu" }
  else
    format.html { render :new }
    format.json { render json: @ajax.errors, status: :unprocessable_entity }
  end
end

end

I have found why was bugging my code. Just nee do remove the flash[:notice] to notice: Now I`m looking into giving a lifetime to this flash, like 10s and it vanishs When I have it working I post it here for other people that may strugle as me