【问题标题】:Selecting a Role from Rolify while using ActiveAdmin使用 ActiveAdmin 时从 Rolify 中选择角色
【发布时间】:2013-12-06 18:34:57
【问题描述】:

将 Rails 4 与 ActiveAdmin 5 以及 CanCan 和 Rolify 结合使用,我希望能够(通过复选框列表或其他方式)在通过 Active Admin 界面编辑或创建新用户时选择将应用于每个用户的角色。

这篇帖子How to use ActiveAdmin on models using has_many through association? 显示了构建表单的方法。虽然我收到错误:

undefined method `new_record?' for nil:NilClass

在执行form do |f| 时仅访问.has_many 属性时似乎会发生这种情况

f.has_many :roles do |app_f|
  #app_f.inputs "Roles" do
    #if !app_f.object.nil?
      # show the destroy checkbox only if it is an existing appointment
      # else, there's already dynamic JS to add / remove new appointments
   #app_f.input :_destroy, :as => :boolean, :label => "Destroy?"
  #row app_f.role.name
  #end

  #  app_f.input :roles # it should automatically generate a drop-down select to choose from your existing patients

  #end
end

【问题讨论】:

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


    【解决方案1】:

    我发现通过 f.input 采用不同的路径访问角色效果更好

    这是工作代码:

      form do |f|
        f.inputs "Admin Details" do
          f.input :email
          f.input :first_name
          f.input :last_name
          f.input :alias
          f.input :bio
          f.input :password
          f.input :password_confirmation
          f.input :roles, :as => :check_boxes
        end
        f.actions
      end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-06
      • 2012-06-06
      • 2021-09-13
      • 1970-01-01
      • 1970-01-01
      • 2012-08-09
      相关资源
      最近更新 更多