dPanda13
dPanda13

Reputation: 275

ActiveAdmin user display bug

I use ActiveAdmin, I have projects and tasks. When I create a new task, the Admin user dropdown displays as # adminuser:0x007fbe6d74deb0. Friends, how to fix it? I would like to simply displaying an email of user.


Rails 4.1.0

ActiveAdmin 1.0.0

ruby 2.1


app/admin/task.rb

ActiveAdmin.register Task do

    scope :all, :default => true      # Defines the default scope, showing all rows 
    scope :due_this_week do |tasks|   # 
      tasks.where('due_date > ? and due_date < ?', Time.now, 1.week.from_now)
    end
    scope :late do |tasks|
      tasks.where('due_date < ?', Time.now)
    end
    scope :mine do |tasks|
      tasks.where(:admin_user_id => current_admin_user.id)
    end

    show do
      panel "Task Details" do
        attributes_table_for task do
          row("Status") { status_tag (task.is_done ? "Done" : "Pending"), (task.is_done ? :ok : :error) }
          row("Title") { task.title }
          row("Project") { link_to task.project.title, admin_project_path(task.project) }
          row("Assigned To") { link_to task.admin_user.email, admin_admin_user_path(task.admin_user) }
          row("Due Date") { task.due_date? ? l(task.due_date, :format => :long) : '-' } 
        end
      end

      active_admin_comments # Provides a simple commenting system for each model. Enabled it here because commenting on a task could be very useful to discuss functionality, or something similar.
    end

    # Creates a sidebar panel, titled “Other Tasks For This User”, which is shown only on the “show” page. 
    # It will show a table for the currentadminuser, and all tasks where the project is the same as the project being shown.

    sidebar "Other Tasks For This User", :only => :show do
      table_for current_admin_user.tasks.where(:project_id => task.project) do |t|
        t.column("Status") { |task| status_tag (task.is_done ? "Done" : "Pending"), (task.is_done ? :ok : :error) }
        t.column("Title") { |task| link_to task.title, admin_task_path(task) }
      end
    end

    permit_params :title, :project_id, :admin_user_id, :due_date, :is_done

  # See permitted parameters documentation:
  # https://github.com/gregbell/active_admin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters
  #
  # permit_params :list, :of, :attributes, :on, :model
  #
  # or
  #
  # permit_params do
  #  permitted = [:permitted, :attributes]
  #  permitted << :other if resource.something?
  #  permitted
  # end

end

Upvotes: 0

Views: 157

Answers (1)

Uri Agassi
Uri Agassi

Reputation: 37409

Your object (AdminUser) should implement one of the below methods:

# Active Admin makes educated guesses when displaying objects, this is
# the list of methods it tries calling in order
setting :display_name_methods, [ :display_name,
                                  :full_name,
                                  :name,
                                  :username,
                                  :login,
                                  :title,
                                  :email,
                                  :to_s ]

(taken from the code)

Upvotes: 2

Related Questions