数据表未在Rails中激活 - 正确的资产管道设置

时间:2014-10-23 00:18:31

标签: jquery ruby-on-rails datatable jquery-datatables

我正在关注用于构建数据表的railscast:http://railscasts.com/episodes/340-datatables?autoplay=true

按照所有步骤,该表仍然呈现与以前相同的静态html:

enter image description here

我之前使用的引导程序与许多其他gems一样,但数据表会为应用程序的可用性添加分配。

我已经发布了我目前正在使用的代码,

可能有什么问题?有没有办法在rails应用程序中调试javascript而不是盲目地做事?

manage.html.erb(注意:在“地点”视图文件夹中):

<% if @restaurant.locations.any? %>
    <h1>Manage <%= @restaurant.name.pluralize %> Restaurant Locations</h1>

    <table id="restaurantLocations">
    <thead>
        <tr>
            <th>Store Number</th>
            <th>Address</th>
            <th>City</th>
            <th>State</th>
            <th>Nearest Bidding City</th>
            <th>Zip Code</th>
            <th>Sit Down?</th>
            <th>Drive Through?</th>
        </tr>
    </thead>
    <%# current_user.locations.each do |branch| %>
    <tbody>
      <% @restaurant.locations.each do |branch| %>
            <tr>
                <td><%= branch.store_number %></td>
                <td><%= branch.address %></td>
                <td><%= branch.city_name %></td>
                <td><%= branch.state.upcase %></td>
                <td><%= Metro.where(id: branch.city_id).pluck(:city).first %></td>
                <td><%= branch.zip %></td>
                <td><%= branch.sit_down %></td>
                <td><%= branch.drive_through %></td>
            </tr>
        <% end %>
    </tbody>
    </table>
<% else %>

    <h1>Upload <%= @restaurant.name.pluralize %> Restaurant Locations</h1>
    <p>Simply format your CSV file as the sample:(INSERT EXAMPLE) and upload</p>
<% end %>

<h2>Import Restaurants</h2>

<%= form_tag import_locations_path(id: @restaurant.id), multipart: true do %>
    <%= file_field_tag :file %>
    <%= submit_tag "Import" %>
<% end %>

的application.js:

//= require jquery
//= require jquery_ujs
//= require chosen-jquery
//= require bootstrap
//= require dataTables/jquery.dataTables
//= require dataTables/bootstrap/2/jquery.dataTables.bootstrap
//= require turbolinks
//= require bootstrap-datepicker
//= require raphael
//= require morris
//= require underscore
//= require gmaps/google
//= require_tree .

applcation.css:

*
 *= require_self
 *= require chosen
 *= require bootstrap-datepicker
 *= require dataTables/jquery.dataTables
 *= require dataTables/bootstrap/2/jquery.dataTables.bootstrap
 *= require_tree .
 */

locations.js.coffee:

jQuery ->
    $("#restaurantLocations").dataTable();

的Gemfile:

# DataTables
gem 'jquery-datatables-rails', github: 'rweng/jquery-datatables-rails'

1 个答案:

答案 0 :(得分:2)

资产管道未加载locations.js.coffee的资产。我通过明确地将//= require 'locations'添加到application.js文件解决了这个问题,现在一切正常:

//= require jquery
//= require jquery.turbolinks
//= require jquery_ujs
//= require jquery-ui
//= require dataTables/jquery.dataTables
//= require bootstrap
//= require dataTables/bootstrap/2/jquery.dataTables.bootstrap
//= require chosen-jquery
//= require bootstrap-datepicker
//= require raphael
//= require morris
//= require underscore
//= require gmaps/google 
//= require 'locations'     <- What I added
//= require_tree .