The RailsTutorial Exercise 10.5.7 asks me to insert a character counter for the micropost form. I’m using this plugin to accomplish the task.
Everything is working, except the character count div is being inserted twice, as you can see in the following screenshot.

I suspect this is happening because I’m using the form_for tag, which takes a block. Here’s the page code:
<%= javascript_include_tag "character-counter", "character-counter-options" %>
<%= form_for(@micropost) do |f| %>
<%= render 'shared/error_messages', object: f.object %>
<div class="field">
<%= f.text_area :content, placeholder: "Compose new micropost...",
id: "new-micropost" %>
</div>
<%= f.submit "Post", class: "btn btn-large btn-primary" %>
<% end %>
I can post the javascript if needed, but like I said, things are working correctly except for the duplication. I haven’t changed any of the plugin code, just my options following the examples included in the plugin source. All of this can be found in the link from the first paragraph.
Update: Here is the javascript I’m using. The plugin code is long, so I opted to put it in a paste. InsertAfter appears in line 38 of the paste. My options are also in the past, but since they’re short, you can read them here as well.
var info;
$(document).ready(function(){
var options = {
'maxCharacterSize': -2,
'warningStyle' : 'warning',
'warningNumber': 40,
'displayFormat' : '#input/140'
};
$('#new-micropost').textareaCount(options);
});
It turns out, since I was including the javascript in the asset pipeline, it was being loaded twice. It was loaded once by the asset pipeline, and then again in my form partial (see the first line of the template code in my OP).
See: $(function) gets called twice in Rails 3.2.1 App
I don’t really need the code on every page, just in that partial, so I’ll move the files out of the asset pipeline. : /