Kad
You have probably already spotted it, but just in case:
respond_to do |format| format.js { if @located page.redirect_to posts_url else render :update do |page| page.replace_html 'error_message', "Error..." page << "$('popup_error').popup.show();" end end } end
In the line - page.redirect, page is out of scope.
Will work if you do:
render :update do |page| if @located page.redirect_to posts_url else page.replace_html 'error_message', "Error..." page << "$('popup_error').popup.show();" end end
The reason it needs to be this way is that redirect does not cause the method to immediately exit, so the other render statements were getting executed, causing the error.
tonypm