Skip to content

Instantly share code, notes, and snippets.

@guinslym
Created December 24, 2013 18:02
Show Gist options
  • Save guinslym/8116345 to your computer and use it in GitHub Desktop.
Save guinslym/8116345 to your computer and use it in GitHub Desktop.
Wrong javascript output. I'm trying to load a form using Javascript. So that when I user click on "new Comment" it will append the 'comment form' but when I clicked on the link it renders $("<form accept-charset=\"UTF-8\" action=\"/articles/3/comments\"...
$("<%= escape_javascript render(:file => 'comments/new.html.erb') %>").insertAfter('#comments');
$('#new_comment_link').hide();
$("<form accept-charset=\"UTF-8\" action=\"/articles/3/comments\" class=\"new_comment\" id=\"new_comment\" method=\"post\"><div style=\"margin:0;padding:0;display:inline\"><input name=\"utf8\" type=\"hidden\" value=\"&#x2713;\" /><input name=\"authenticity_token\" type=\"hidden\" value=\"zSq3KpEbucFQLa6XStEJ/I0+CpKPLFYcU/WGIdneeMg=\" /><\/div>\n<div class=\"field\">\n<label for=\"comment_name\">Name<\/label><br />\n<input id=\"comment_name\" name=\"comment[name]\" type=\"text\" />\n<\/div>\n<div class=\"field\">\n<label for=\"comment_email\">Email<\/label><br />\n<input id=\"comment_email\" name=\"comment[email]\" type=\"text\" />\n<\/div>\n<div class=\"field\">\n<label for=\"comment_body\">Body<\/label><br />\n<textarea id=\"comment_body\" name=\"comment[body]\">\n<\/textarea>\n<\/div>\n<div class=\"actions\">\n<input name=\"commit\" type=\"submit\" value=\"Add\" />\n<\/div>\n<\/form>").insertAfter('#comments');
$('#new_comment_link').hide();
<%= render @article %>
<h3>Comments</h3>
<div id="comments">
<%= render @article.comments %>
</div>
<%= link_to "new comment", new_article_comment_path(@article, :format => :js), :remote => true, :id => 'new_comment_link' %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment