我使用ActiveAdmin,我有项目和任务。当我创建新任务时,管理员用户下拉列表显示为# adminuser:0x007fbe6d74deb0 。朋友,如何解决?我想简单地显示用户的电子邮件。
Rails 4.1.0
ActiveAdmin 1.0.0
ruby 2.1
应用/管理/ 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
答案 0 :(得分:2)
您的对象(AdminUser
)应实现以下方法之一:
# 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 ]
(摘自code)