10

フォームをリモートに変更したところ、フォームは機能するようになりましたが、エラーが発生した場合にエラー メッセージが表示されなくなりました。

<%= render 'shared/error_messages' %>

メッセージを再び表示するのに適したウェアはありますか?

以下は私のコントローラーです...

ありがとうございました。

respond_to do |format|
  if @post.save
    format.js { render :js => "window.location = '#{edit_post_path @post}'" }
    format.html { redirect_to [:edit, @post] }
  else
    format.js { render :js => @post.errors }
    format.html { redirect_to '/', :error => "Could not save comment" }      
  end
end
4

1 に答える 1

13
respond_to do |format|
  if @post.save
    format.js { render :js => "window.location = '#{edit_post_path @post}'" }
    format.html { redirect_to [:edit, @post] }
  else
    format.js { }
    format.html { redirect_to '/', :error => "Could not save comment" }      
  end
end

# update.js.erb

$(document).find("form").prepend('<%= escape_javascript(render("shared/error_messages", :formats => [:html])) %>');
于 2012-12-18T01:01:29.557 に答える