Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

render error messages with js form rails

I changed my form to remote, and while the form now works, the error messages are no longer displaying if there's an error.

<%= render 'shared/error_messages' %>

is there a good wear to get the messages to show again?

below is my controller...

thank you.

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
like image 756
user749798 Avatar asked Dec 18 '12 00:12

user749798


1 Answers

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])) %>');
like image 144
Valery Kvon Avatar answered Oct 22 '22 17:10

Valery Kvon