Problem with escape_javascript using :default javascript
I was doing some ajax functionality when i came up to this problem on the create action.
In my create.js.erb:
$("follow_form").update('<%= escape_javascript(render("users/unfollow")) %>')
$("followers").update('<%= "#{@user.followers.count} followers" %> ')
where my partial users/_unfollow.html.erb:
<%= form_for(current_user.relationships.find_by_followed_id(@user),
:html => { :method => :delete },
:remote => true) do |f| %>
<div class='actions'>
<%= f.submit 'Unfollow' %>
</div>
<% end %>
Basically the "follow" button will turn to "unfollow" when it is clicked. However when the button is clicked, this is what escape_javascript returns:
<form accept-charset=UTF-8 action=/relationships class=new_relationship data-remote=true id=new_relationship method=post>
<div style=margin:0;padding:0;display:inline>
<input name=utf8 type=hidden value=✓ />
<input name=authenticity_token type=hidden value=YwOC5/xVq5FQFJxOiKXR8nGV7/jGMsVEX4OLuWJB56I= />
div>
<div>
<input id=relationship_followed_id name=relationship[followed_id] type=hidden value=7 />
div>
<div class=actions>
<input id=relationship_sub开发者_运维知识库mit name=commit type=submit value=Follow />
div>
form>
You can see that just about every closing tag is missing '< /'. Thus the button will not work.
then i started playing around with the javascript includes. And this ajax functionality will work when i change
<%= javascript_include_tag :defaults %>
to
<%= javascript_include_tag 'prototype' %>
why is this behaving this way?
精彩评论