Rails3和jQuery-绑定此javascript

问题描述

| 我正在使用Rails3并安装了最新的jQuery插件。我正在尝试获取字符。 count函数从下面的代码运行,但是没有成功。任何帮助,将不胜感激?? article / _form.html.erb
<div class=\"field\">
<%= f.label :title %><br />
<%= f.text_field :title %>
</div>

<div class=\"field\">
<%= f.label :body %><br />
<%= f.text_area :body id=testTextarea2 %>
</div>

<div class=\"field\">
<%= f.label :tag_names,\"Tags\" %>  <br />
<%= f.text_field :tag_names %> 
</div>
layouts / application.html.erb
<Meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />
 <title>myblog.com</title>
   <%= stylesheet_link_tag \'scaffold\' %>
   <%= stylesheet_link_tag \'screen\',:media => \'screen\' %>
   <%= stylesheet_link_tag \'print\',:media => \'print\' %>
   <%= javascript_include_tag :defaults,\"jquery.js\",\"counter.js\",\"rails.validations\" %>
   <%= csrf_Meta_tag %>
   <script src=\"/javascripts/jquery.textareaCounter.plugin.js\" type=\"text/javascript\"></script>


<script type=\"text/javascript\">
var info;
$(document).ready(function()    {

       var options = {  
        \'maxCharacterSize\': -2,\'originalStyle\': \'originalTextareaInfo\',\'warningStyle\' : \'warningTextareaInfo\',\'warningNumber\': 40
        };
        $(\'#testTextarea\').textareaCount(options);


       var options2 = {
        \'maxCharacterSize\': 200,\'warningNumber\': 40,\'displayFormat\' : \'#input/#max | #words words\'
        };
        $(\'#testTextarea2\').textareaCount(options2);


       var options3 = {
        \'maxCharacterSize\': 200,\'displayFormat\' : \'#left Characters Left / #max\'
        };
        $(\'#testTextarea3\').textareaCount(options3,function(data)

                    {
        $(\'#showData\').html(data.input + \" characters input. <br />\" + data.left + \" characters left. <br />\" + data.max + \" max characters. <br />\" + data.words + \" words input.\");
            });
        });
</script>
SyntaxError in Articles#new

Showing /Users/blog/app/views/articles/_form.html.erb where line #23 raised:

compile error
/Users/blog/app/views/articles/_form.html.erb:23: Syntax error,unexpected tIDENTIFIER,expecting \')\'
...append= ( f.text_area :body id=\"testTextarea2\" );@output_buf...
                          ^
Extracted source (around line #23):

20: 
21:   <div class=\"field\">
22:     <%= f.label :body %><br />
23:     <%= f.text_area :body id=\"testTextarea2\" %>
24:   </div>
25:  
    

解决方法

您看到的错误与jQuery或JS无关。 text_area帮助程序需要属性的哈希-这应该使您摆脱错误:
f.text_area :body,:id => \"testTextarea2\"
    ,我希望看到以下html在某处生成,它在哪里-您没有显示该代码吗?
 <textarea id=\"testTextarea\" cols=\"60\" rows=\"10\" ></textarea>
 <div class=\"originalTextareaInfo warningTextareaInfo\">

 <textarea id=\"testTextarea2\" cols=\"60\" rows=\"10\" ></textarea>
 <div class=\"originalTextareaInfo warningTextareaInfo\">

 <textarea id=\"testTextarea3\" cols=\"60\" rows=\"10\" ></textarea>
 <div class=\"originalTextareaInfo warningTextareaInfo\">
 <div id=\"showData\"></div>