【问题标题】:ActiveAdmin user display bugActiveAdmin 用户显示错误
【发布时间】:2014-05-19 22:11:26
【问题描述】:

我使用 ActiveAdmin,我有项目和任务。当我创建新任务时,管理员用户下拉菜单显示为 # adminuser:0x007fbe6d74deb0。朋友,怎么解决?我想简单地显示用户的电子邮件。


Rails 4.1.0

ActiveAdmin 1.0.0

红宝石 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

【问题讨论】:

    标签: ruby ruby-on-rails-4 activeadmin


    【解决方案1】:

    您的对象 (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

    【讨论】:

    • 有效!我为我的 admin_user 实现了一个 :to_s,现在一切正常,非常感谢;)
    猜你喜欢
    • 1970-01-01
    • 2016-05-01
    • 1970-01-01
    • 2014-12-05
    • 2015-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-12
    相关资源
    最近更新 更多