In my Rails app, I want to render the flash message from my controller method delete_option
(questions_controller
) to a partial _edit.html.erb
inside questions folder itself. I have a js file delete_option.js.erb
and I could successfully render the edit using the below line to a div element with id edit_subquestion
.
$("#edit_subquestion").html("<%= escape_javascript(render(:partial => "edit")) %>");
I put a div element inside the _edit.html.erb
to render the flash message as given below.
<div id="flash_delete_option"></div>
I am trying to render the flash message from the method delete_option
to the above div
element as given below.
if((<%=flash[:success]%>).length > 0)
$("#flash_delete_option").html("<%= escape_javascript(render('<%=flash[:success]%>')) %>");
I am getting syntax errors. Please help to resolve this. Everything tried as per the answer. Not getting it.
Jesse Wolgamott : if loop was the problem. I modified it. now, its working.
You can use ruby to do conditionals in your edit.js.erb file. Also, since you're inside the escape_javascript, you don't call render in there.