2015-06-19 70 views
0

我试图在我的Rails应用程序中实现动态选择菜单,遵循YouTube视频#88。Rails中的动态选择菜单

我设置了一切像视频,但我的JavaScript不工作,因为它应该。

我的视图代码:_form.html.erb

<div class="field"> 
    <%= f.label :cliente_id %><br> 
    <%= f.collection_select :cliente_id, Cliente.order(:name), :id, :name, include_blank: true %> 
</div> 
<div class="field"> 
    <%= f.label :projeto_id %><br> 
    <%= f.grouped_collection_select :projeto_id, Cliente.order(:name), :projetos, :name, :id, :name, include_blank: true %> 
</div> 

relatos.coffe - >

JQuery -> 
    projetos = $('#relato_projeto_id').html() 
    $('#relato_cliente_id').change -> 
    cliente = $('#relato_cliente_id :selected').text() 
    options = $(projetos).filter("optgroup[label='#{cliente}']").html() 
    if options 
     $('#relato_projeto_id').html(options) 
    else 
     $('#relato_projeto_id').empty() 

该网页似乎正常,没有错误,但是当我列出了Cliente(客户端)它应该列出只列出给他的项目,但它一直显示所有项目,因为根本没有jQuery。

+1

请确认js文件的扩展名是“.coffee”而不是“.coffe” –

+0

发布生成的HTML,与rails相反,因为它没有帮助。 – lshettyl

+0

CoffeeScript是缩进敏感的。你所提供的不是语法上有效的。 –

回答

0

代码的开始是JQuery,它应该是jQuery。感谢之前说过的人,但现在我明白了。