1

In my app I have categories and labels they both belongs to products

In the admin panel the user can add products, and create labels and categories and then assign categories and labels to products.

When I create labels the names are displaying correctly in the Label Panel( see photo)

enter image description here

The Problem is that the labels name aren't displaying right when they are assign to products(see photo below) but the categories names are displaying. This is strange because both columns have the same setup.

And in the Admin products panel the labels are displaying with numbers Label#1``Label#2etc (see photo below)

And in the _navbar.html.erb I have this code to display Both Categories and Labels... and it is displaying correctly in there.

                <ul class="dropdown-menu" role="menu">
                    <% @categories.each do |category| %>
                        <li><%= link_to category.name, category %></li>
                    <% end %>         
                </ul>
            </li>       
              <li class="dropdown full-width">
                <a href="#" class="dropdown-toggle" 
                data-toggle="dropdown">
                    Labels
                </a>
                <ul class="dropdown-menu" role="menu">
                   <% @labels.each do |label| %>
                        <li><%= link_to label.label_name, label %></li>
                    <% end %>    
                </ul>
            </li>       

Am I missing something here? I can't see why the labels aren't displaying correctly.

Have anyone had the same or similar problem with active admin?

Can anyone take a look at this?

Thanks in advance

enter image description here

enter image description here

enter image description here

This is the app/admin/category.rb

ActiveAdmin.register Category do

 permit_params :name

end

In the app/admin/label.rb there is this code:

ActiveAdmin.register Label do

 permit_params :label_name

end

And in the app/admin/product.rb

ActiveAdmin.register Product do


 permit_params :title, :description, :image, :price_usd, :price_isl, :category_id, :label_id

 index do
    column :title
    column :category
    column :label
    column :created_at

    column :price_isl, :sortable => :price_isl do |product|
        number_to_currency product.price_isl
    end
    column :price_usd, :sortable => :price_usd do |product|
        number_to_currency product.price_usd
    end

    actions
end
end

Then here are parts of the Schema.rb

create_table "labels", force: :cascade do |t|
  t.string   "label_name"
  t.datetime "created_at", null: false
  t.datetime "updated_at", null: false
end

create_table "categories", force: :cascade do |t|
  t.string   "name"
  t.datetime "created_at", null: false
  t.datetime "updated_at", null: false
end

2 Answers 2

7

Active Admin makes educated guesses when displaying objects.

This is the list of methods it tries calling in order

  • display_name
  • full_name
  • name
  • username
  • login
  • title
  • email
  • to_s

So, it works with categories since Category has :name attribute.

For labels you can do the following:

class Label < ActiveRecord::Base
    def display_name
      label_name
    end
end

You can also configure displayed names in ActiveAdmin initializer:

ActiveAdmin.setup do |config|    
  config.display_name_methods = [:display_name, :full_name, :name, ..., :to_s]
end
0

Active Admin can sometimes be tricky with naming...In your categoriestable you have a column called :name which seems to be working like you want it to?

have you tried to change the label_namecolumn in the labels.rbto just names?

I'm pretty sure that will do the trick for you.

Active Admin is most likely not registering the underscore between labeland nameand thats way its displaying things like it is.

1
  • Thank you sometimes it's the simple things that you don´t see :) It's working perfectly now
    – DaudiHell
    Sep 30, 2016 at 15:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.