table_for with no items displays "[]" #1016

Closed
djwonk opened this Issue Feb 14, 2012 · 12 comments

Comments

Projects
None yet
6 participants
@djwonk

djwonk commented Feb 14, 2012

In a show page for one object, where a table_for is used to display associated items, it displays "[]" instead of just making an empty table.

Source code example, in my cases.rb file:

ActiveAdmin.register Case do

# ...

panel "Notes" do
  table_for(c.case_notes) do |t|
    t.column("Note ID", :id) do |case_note|
      link_to(case_note.pretty_id, admin_case_note_path(case_note))
    end
    t.column("Contact ID") do |case_note|
      contact = case_note.contact
      if contact
        link_to(contact.pretty_id, admin_contact_path(contact))
      else
        "n/a"
      end
    end
    # ...
@djwonk

This comment has been minimized.

Show comment Hide comment
@djwonk

djwonk Feb 14, 2012

The associated html is:

       <div class="panel">
          <h3>Notes</h3>
          <div class="panel_contents">
            <table border="0" cellspacing="0" cellpadding="0">
              <thead>
                <tr>
                  <th class="">Note ID</th>
                  <th class="">Contact ID</th>
                  <th class="">CSR</th>
                  <th class="note">Note</th>
                </tr>
              </thead>
              <tbody>[]</tbody>
            </table>
          </div>
        </div>

djwonk commented Feb 14, 2012

The associated html is:

       <div class="panel">
          <h3>Notes</h3>
          <div class="panel_contents">
            <table border="0" cellspacing="0" cellpadding="0">
              <thead>
                <tr>
                  <th class="">Note ID</th>
                  <th class="">Contact ID</th>
                  <th class="">CSR</th>
                  <th class="note">Note</th>
                </tr>
              </thead>
              <tbody>[]</tbody>
            </table>
          </div>
        </div>
@djwonk

This comment has been minimized.

Show comment Hide comment
@djwonk

djwonk Feb 14, 2012

I hacked out the offending stray text using jQuery:

$(document).ready(function() {
  var panel = $('div.panel_contents');
  panel.each(function(index) {
    var contents = $(this).contents();
    var shady = $(contents[0]);
    shady.detach();
  });
});

djwonk commented Feb 14, 2012

I hacked out the offending stray text using jQuery:

$(document).ready(function() {
  var panel = $('div.panel_contents');
  panel.each(function(index) {
    var contents = $(this).contents();
    var shady = $(contents[0]);
    shady.detach();
  });
});

@ghost ghost assigned gregbell Feb 14, 2012

@gregbell

This comment has been minimized.

Show comment Hide comment
@gregbell

gregbell Feb 14, 2012

Contributor

What version of active admin are you using? I can't seem to replicate it on master.

Contributor

gregbell commented Feb 14, 2012

What version of active admin are you using? I can't seem to replicate it on master.

@pwightman

This comment has been minimized.

Show comment Hide comment
@pwightman

pwightman Feb 14, 2012

For what it's worth, I'm experiencing this same issue on 0.3.4: http://cl.ly/1G151a2W2B1m3W0W0v0h

For what it's worth, I'm experiencing this same issue on 0.3.4: http://cl.ly/1G151a2W2B1m3W0W0v0h

@djwonk

This comment has been minimized.

Show comment Hide comment
@djwonk

djwonk Feb 15, 2012

I'm using 0.4.0.

On Tue, Feb 14, 2012 at 5:18 PM, Greg Bell
reply@reply.github.com
wrote:

What version of active admin are you using? I can't seem to replicate it on master.


Reply to this email directly or view it on GitHub:
gregbell#1016 (comment)

djwonk commented Feb 15, 2012

I'm using 0.4.0.

On Tue, Feb 14, 2012 at 5:18 PM, Greg Bell
reply@reply.github.com
wrote:

What version of active admin are you using? I can't seem to replicate it on master.


Reply to this email directly or view it on GitHub:
gregbell#1016 (comment)

@djwonk

This comment has been minimized.

Show comment Hide comment
@djwonk

djwonk Feb 15, 2012

I tried setting my Gemfile to point to the github version of activeadmin. This didn't solve the problem.

Can you point me to the code that I should examine more closely? I don't mind digging in, but a few pointers would help.

djwonk commented Feb 15, 2012

I tried setting my Gemfile to point to the github version of activeadmin. This didn't solve the problem.

Can you point me to the code that I should examine more closely? I don't mind digging in, but a few pointers would help.

@latortuga

This comment has been minimized.

Show comment Hide comment
@latortuga

latortuga Feb 15, 2012

Contributor

@djwonk I tried looking into this a bit and couldn't figure it out on first walkthrough. The code in question can be found here https://github.com/gregbell/active_admin/blob/master/lib/active_admin/views/components/table_for.rb

You also might want to look in the arbre directory as that's where the HTML is mainly generated (https://github.com/gregbell/active_admin/tree/master/lib/active_admin/arbre)

My suspicion is that it has to do with default return values from some of the functions as otherwise why would a blank array show up? As an initial idea, perhaps the call to build_table should not be performed if the collection is empty.

I've had this problem on 0.3.4 and 0.4.0.

Contributor

latortuga commented Feb 15, 2012

@djwonk I tried looking into this a bit and couldn't figure it out on first walkthrough. The code in question can be found here https://github.com/gregbell/active_admin/blob/master/lib/active_admin/views/components/table_for.rb

You also might want to look in the arbre directory as that's where the HTML is mainly generated (https://github.com/gregbell/active_admin/tree/master/lib/active_admin/arbre)

My suspicion is that it has to do with default return values from some of the functions as otherwise why would a blank array show up? As an initial idea, perhaps the call to build_table should not be performed if the collection is empty.

I've had this problem on 0.3.4 and 0.4.0.

@pcreux

This comment has been minimized.

Show comment Hide comment
@pcreux

pcreux Feb 18, 2012

Contributor

This happens on ruby 1.9 only because [].to_s returns "[]" on 1.9.

Contributor

pcreux commented Feb 18, 2012

This happens on ruby 1.9 only because [].to_s returns "[]" on 1.9.

@jancel

This comment has been minimized.

Show comment Hide comment
@jancel

jancel Feb 18, 2012

Contributor

This is fixed in master. Slated for 0.4.2.

Contributor

jancel commented Feb 18, 2012

This is fixed in master. Slated for 0.4.2.

@djwonk

This comment has been minimized.

Show comment Hide comment
@djwonk

djwonk Feb 18, 2012

Thanks for fixing this!

I just want to mention that the behavior difference isn't just for []. It applies to all arrays.

In Ruby 1.8.7:

[1,2,3].to_s #=> "123"

In Ruby 1.9.3:

[1,2,3].to_s #=> "[1, 2, 3]"

Hopefully the code takes this into account.

djwonk commented Feb 18, 2012

Thanks for fixing this!

I just want to mention that the behavior difference isn't just for []. It applies to all arrays.

In Ruby 1.8.7:

[1,2,3].to_s #=> "123"

In Ruby 1.9.3:

[1,2,3].to_s #=> "[1, 2, 3]"

Hopefully the code takes this into account.

@jancel

This comment has been minimized.

Show comment Hide comment
@jancel

jancel Feb 19, 2012

Contributor

Change only affects empty arrays. Arrays should work the same as they always have.

Contributor

jancel commented Feb 19, 2012

Change only affects empty arrays. Arrays should work the same as they always have.

@pcreux

This comment has been minimized.

Show comment Hide comment
@pcreux

pcreux Feb 19, 2012

Contributor

Closed by 2d70197

Contributor

pcreux commented Feb 19, 2012

Closed by 2d70197

@pcreux pcreux closed this Feb 19, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment