Ruby on Rails DataTable now working.

Posted by Nimroo on Stack Overflow See other posts from Stack Overflow or by Nimroo
Published on 2012-12-04T23:01:47Z Indexed on 2012/12/04 23:03 UTC
Read the original article Hit count: 230

Filed under:
|
|

[Ruby on Rails DataTable guide][1]https://github.com/phronos/rails_datatables/blob/master/README.md

I"m following the above and have installed the git plugin as well. All i'm getting is the <%= datatable() %> returning " <script type="text/javascript"> $(function() { $('#expenses').dataTable({ "oLanguage": { "sSearch": "Search", "sProcessing": 'Processing' }, "sPaginationType": "full_numbers", "iDisplayLength": 25, "bProcessing": true, "bServerSide": false, "bLengthChange": false, "bStateSave": true, "bFilter": true, "bAutoWidth": true, 'aaSorting': [[0, 'desc']], "aoColumns": [ { 'sType': 'html', 'bSortable':true, 'bSearchable':true ,'sClass':'first' },{ 'sType': 'html', 'bSortable':true, 'bSearchable':true },{ 'sType': 'html', 'bSortable':true, 'bSearchable':true },{ 'sType': 'string', 'bSortable':true, 'bSearchable':true ,'sClass':'last' } ], "fnServerData": function ( sSource, aoData, fnCallback ) { aoData.push( ); $.getJSON( sSource, aoData, function (json) { fnCallback(json); } ); } }); }); </script>".

My .html.erb looks like this:

<% @page_title="User Page"%> 

   <link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" />
    <script src="http://code.jquery.com/jquery-1.8.3.js"></script>
    <script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
     <%=javascript_include_tag "jquery.dataTables" %>
     <%=stylesheet_link_tag "jquery-ui-1.9.2.custom" %>

    <script>
    $(function() {
        $( "#tabs" ).tabs();
    });
    </script>

<% if current_user %>
<div id="tabs">
    <ul>
        <li><a href="#tabs-1">Expenses</a></li>
        <li><a href="#tabs-2">Accountant</a></li>
        <li><a href="#tabs-3">Requests (<%[email protected]%>)</a></li>    
    </ul>
     <div id="tabs-3">
       <p>
        <% if @requests.count != 0 %>
        <h2> Accountant Requests </h2>

        <table >
          <tr>
              <thead>

            <th>First Name</th>
            <th>Last Name</th>
            <th>Email Address</th>
            <th>Accept</th>
            <th>Reject</th>
                </thead>
          </tr>

          <% @requests.each do |request| %>
            <tr>
            <td><%= request.accountant.first_name %></td>
            <td><%= request.accountant.last_name %></td>
            <td><%= request.accountant.email %></td>
            <td><%= link_to 'accept', confirm_accountant_path(:accountant_id => request.accountant_id) %></td>
            <td><%= link_to 'Edit', edit_expense_path(request) %></td>      
            </tr>
          <% end %>
        </tbody>
        </table>
        <% else %>
            <h4> You have no pending requests <h4>
        <% end %>
        </p>
    </div>
    <div id="tabs-2">
       <p>
        <% if @accountants.count != 0 %>
        <h2> Accountant Info </h2>

        <table>
          <tr>
            <th>First Name</th>
            <th>Last Name</th>
            <th>Email Address</th>
          </tr>
          <% @accountants.each do |accountant| %>
            <tr>
            <td><%= accountant.first_name %></td>
            <td><%= accountant.last_name %></td>
            <td><%= accountant.email %></td>        
            </tr>
          <% end %>
        </table>
        <% else %>
            <h4> Add Accountant  <h4>
            <p> You don't have an accountant yet, perhaps consider adding one by e-mail </p>
            <%= render 'add_accountant_form' %>
            <% end %>
        <% end %>
        </p>
    </div>
    <div id="tabs-1">
        <p><% if current_user %>
    <h4> Submit new expense </h4>
    <%= render 'expenses/form' %>
     <% columns = [{:type => 'html', :class => "first"}, {:type => 'html'}, 
    {:type => 'html'}, {:type => nil, :class => "last"}] %>
<%= datatable(columns, {:sort_by => "[0, 'desc']", table_dom_id:"expenses" }) %>
    <table id="expenses" class="datatable">
        <thead>
      <tr>
        <th>Entry Date</th>
        <th>Last Update</th>
        <th>Amount</th>
        <th>User</th>
        <th>Receipt</th>
        <th></th>
        <th></th>
      </tr>
        </thead>
        <% @expenses.each do |user_expense| %>

<tbody>
      <tr>
        <td><%= user_expense.created_at %></td>
        <td><%= user_expense.updated_at %></td>
        <td><%= user_expense.amount %></td>
        <td><%= user_expense.user.username %></td>
            <% if !user_expense.receipt_img.nil? %>
                <td><%= image_tag user_expense.receipt_img.url(:thumb) %></td>
            <% else %>
                <td>Future Button Here</td>
            <% end %>
        <td><%= link_to 'Show', user_expense %></td>
        <td><%= link_to 'Edit', edit_expense_path(user_expense) %></td>
      </tr>
     </tbody>
        <% end %>
    </table>
<% end %></p>
    </div>

</div>

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby