Javascript 在使用rails 4.0的表单_中选择值后,Coffeescript不会显示警报

Javascript 在使用rails 4.0的表单_中选择值后,Coffeescript不会显示警报,javascript,ruby-on-rails,coffeescript,ruby-on-rails-4,Javascript,Ruby On Rails,Coffeescript,Ruby On Rails 4,我正在使用form_作为a:quote资源。我想在第一个字段(acollection\u select)更改后执行操作。我还为自行车使用了字段,其中有很多引号 这是我现在的代码: quotes/new.html: <% provide(:title, 'New Quote') %> <h1>Get a Quote</h1> <div class="row"> <div class="span6 offset3"> <%

我正在使用
form_作为
a
:quote
资源。我想在第一个字段(a
collection\u select
)更改后执行操作。我还为自行车使用了
字段,其中
有很多引号

这是我现在的代码:

quotes/new.html:

<% provide(:title, 'New Quote') %>
<h1>Get a Quote</h1>
<div class="row">
  <div class="span6 offset3">
    <%= form_for @quote do |f| %>
        <% if object.errors.any? %>
            <div id="error_explanation">
                <div class="alert alert-error">
                    The form contains <%= pluralize(object.errors.count, "error") %>.
                </div>
                <ul>
                    <% object.errors.full_messages.each do |msg| %>
                        <li>* <%= msg %></li>
                    <% end %>
                </ul>
            </div>
        <% end %>
        <%= f.fields_for :bikes do |builder| %>
            <%= f.label :make, 'Make' %>
            <%= f.collection_select :make, Bike.unique_by_make, :id , :make %>

            <%= f.label :model, 'Model' %>
            <%= f.text_field :model %>

            <%= f.label :year_manufactured, 'Year' %>
            <%= f.date_field :year_manufactured %>
        <% end %>
        <%= f.submit "Show Quote", class: "btn btn-large btn-primary" %>
    <% end %>
  </div>
</div>
<%= link_to 'Back', quotes_path %>

我使用的是
#quote_bikes_make
,因为我在呈现的HTML中看到了这一点:
select id=“quote_bikes_make”
@mu太短了,因为我需要将咖啡脚本放在一个现成的挂钩中(请参阅上面更新的代码)。然而,单凭这一点并不能解决问题。我安装了完成这一任务的

当您尝试使用时,DOM中是否有
\quote\u bikes\u make
?我不确定如何测试DOM中是否有
\quote\u bikes\u make
。。。。我现在在谷歌上搜索。只需一个
控制台.log($('quote\u bikes\u make').length)
在你的
$('quote\u bikes\u make')上方。更改->
是一种快速的检查方法。如果上面写的是0,那么它就不存在了。好吧,我添加了它,在我的浏览器js控制台中,输出是0。所以我猜它不在DOM中。您只需要运行
$(…)。在文档就绪挂钩中更改->
内容,请参阅以获取一些选项。jquery-turbolinks补丁
$(文档)。准备好了解turbolinks事件了吗?
ready = ->
    $('#quote_bikes_make').change ->
        chosen = $(this).find(":make")
        alert chosen.data("desc")
$(document).ready(ready)
$(document).on('page:load', ready)