【问题标题】:Display in a column the first three letters of the name + id在一列中显示名称 + id 的前三个字母
【发布时间】:2019-01-21 11:14:17
【问题描述】:

我在 Rails 中使用Activeadmin。例如我想在一列中显示姓名+id的前三个字母 这是一段代码

ActiveAdmin.register User do

 permit_params: email,: name,: firstname,: mailsent,: 
 email_confirmed,: adminuser,: approved

 index do
  column: email
  column: name
  column: firstname
  column: mailsent
  column: email_confirmed
  column: adminuser
  column: approved
  actions
 end

【问题讨论】:

  • 顺便问一下你有什么问题?
  • 如何更改列:电子邮件仅显示前 3 个字母 + id ?

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


【解决方案1】:

你应该使用

column "Custom Title" do |user|
  "#{user.name.first(3)-#{user.id}"
end

当然,我建议您将"#{user.name.first(3)-#{user.id}" 提取到 User 模型或装饰器中。

【讨论】:

    猜你喜欢
    • 2016-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多